atcoder#ABC280F. [ABC280F] Pay or Receive

[ABC280F] Pay or Receive

Score : 500500 points

Problem Statement

There are NN towns numbered 1,,N1,\ldots,N and MM roads numbered 1,,M1,\ldots,M.

Road ii connects towns AiA_i and BiB_i. When you use a road, your score changes as follows:

  • when you move from town AiA_i to town BiB_i using road ii, your score increases by CiC_i; when you move from town BiB_i to town AiA_i using road ii, your score decreases by CiC_i.

Your score may become negative.

Answer the following QQ questions.

  • If you start traveling from town XiX_i with initial score 00, find the maximum possible score when you are at town YiY_i. Here, if you cannot get from town XiX_i to town YiY_i, print nan instead; if you can have as large a score as you want when you are at town YiY_i, print inf instead.

Constraints

  • 2N1052\leq N \leq 10^5
  • 0M1050\leq M \leq 10^5
  • 1Q1051\leq Q \leq 10^5
  • 1Ai,Bi,Xi,YiN1\leq A_i,B_i,X_i,Y_i \leq N
  • 0Ci1090\leq C_i \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM QQ

A1A_1 B1B_1 C1C_1

\vdots

AMA_M BMB_M CMC_M

X1X_1 Y1Y_1

\vdots

XQX_Q YQY_Q

Output

Print QQ lines as specified in the Problem Statement. The ii-th line should contain the answer to the ii-th question.

5 5 3
1 2 1
1 2 2
3 4 1
4 5 1
3 5 2
5 3
1 2
3 1
-2
inf
nan

For the first question, if you use road 55 to move from town 55 to town 33, you can have a score 2-2 when you are at town 33. Since you cannot make the score larger, the answer is 2-2.

For the second question, you can have as large a score as you want when you are at town 22 if you travel as follows: repeatedly "use road 22 to move from town 11 to town 22 and then use road 11 to move from town 22 to town 11" as many times as you want, and finally use road 22 to move from town 11 to town 22.

For the third question, you cannot get from town 33 to town 11.

2 1 1
1 1 1
1 1
inf

The endpoints of a road may be the same, and so may the endpoints given in a question.

9 7 5
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6
4 3
3 8
3 2
7 9
inf
nan
nan
inf
-9