Ray is planning something and needs your help. Ray needs your help to answer
For the -1
instead. A walk is similar to a path, but edges (and nodes) can be traversed multiple times. The weight of a walk is equal to the sum of weights of the edges it traverses, and if an edge is traversed multiple times, its weight will count multiple times towards the sum.
Constraints
There may be duplicate edges and/or self-loops.
Subtask 1 [25%]
Subtask 2 [35%]
Subtask 3 [40%]
No additional constraints.
Input Specification
The first line contains the integers
The next
The next
Output Specification
For each query -1
instead. The output of each query should be on a separate line.
Sample Input
5 7 7
2 1 1
1 2 3
1 4 10
4 5 1
3 4 1
2 3 4
3 5 5
2 4 2
2 4 6
2 4 7
2 5 3
3 5 1
3 5 2
3 5 3
Sample Output
5
13
-1
6
5
2
-1
Sample Explanation
Here are the answers to each query:
2 4 2
:2 4 6
:2 4 7
: It can be shown that no such walk exists.2 5 3
:3 5 1
:3 5 2
:3 5 3
: It can be shown that no such walk exists.
Comments