Evan is planning a new country. In his ideal country, there are
Evan wants to keep the provinces as segregated as possible for reasons we dare not know about. As such, he has decided that there will only be
Soon after, Evan is told that with his current plan, not every province can visit every other province. Realizing his mistake, he has decided that all roads between any two provinces will be upgraded to be bidirectional. The distance between city
With the country's roads planned out, Evan wants you to find the distance between two cities so that he can decide if any other roads need to be built. He will ask you
Input Specification
The first line will contain three space-separated integers,
The next
The next
It is guaranteed that
Constraints
Subtask 1 [8%]
Subtask 2 [16%]
Subtask 3 [16%]
Subtask 4 [60%]
No additional constraints.
Output Specification
For each query, output the minimum distance from
Sample Input 1
10 13 5
1 2 3
2 3 2
3 1 10
4 1 5
3 4 7
10 3 2
6 10 1
6 7 8
5 7 7
5 6 4
7 8 6
8 9 9
9 5 1
1 8
3 1
9 10
5 2
4 6
Sample Output 1
22
10
6
20
13
Sample Input 2
9 12 4
1 2 1
2 1 1
1 3 1
3 4 1
4 3 1
2 5 1
5 6 1
6 5 1
6 7 1
6 8 1
8 9 1
9 8 1
1 9
7 4
2 8
6 3
Sample Output 2
5
6
3
4
Sample Input 3
14 19 7
1 2 1
2 3 5
3 1 3
2 4 2
4 5 4
5 4 1
4 10 8
10 11 10
11 12 5
12 11 6
4 6 3
6 7 1
7 8 3
8 9 2
9 6 1
8 6 4
7 13 2
13 14 5
14 13 1
1 8
13 12
5 9
11 3
7 4
2 14
10 6
Sample Output 3
10
34
10
25
9
13
11
Comments
RIP evening.
Is the distance we have to find, the minimum possible distance?
Yes