atcoder#ABC280F. [ABC280F] Pay or Receive
[ABC280F] Pay or Receive
Score : points
Problem Statement
There are towns numbered and roads numbered .
Road connects towns and . When you use a road, your score changes as follows:
- when you move from town to town using road , your score increases by ; when you move from town to town using road , your score decreases by .
Your score may become negative.
Answer the following questions.
- If you start traveling from town with initial score , find the maximum possible score when you are at town .
Here, if you cannot get from town to town , print
nan
instead; if you can have as large a score as you want when you are at town , printinf
instead.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines as specified in the Problem Statement. The -th line should contain the answer to the -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 to move from town to town , you can have a score when you are at town . Since you cannot make the score larger, the answer is .
For the second question, you can have as large a score as you want when you are at town if you travel as follows: repeatedly "use road to move from town to town and then use road to move from town to town " as many times as you want, and finally use road to move from town to town .
For the third question, you cannot get from town to town .
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