Time limit
4s
Memory limit
1024 MB
Sehun and Chanwoo have solved many graph problems and developed their own ideas about what makes a good one.
A graph satisfying both conditions is called a 1 && 3 graph. You are given a 1 && 3 graph with V vertices and E edges. Write a program that processes Q queries asking for the shortest distance between two vertices.
The first line contains three integers V, E, and Q: the number of vertices, the number of edges, and the number of queries. (2≤V≤500000;V−1≤E≤500000;1≤Q≤200000)
Each of the next E lines contains three integers x, y, and c, meaning that there is an edge of weight c between vertices x and y. (1≤x,y≤V;1≤c≤109;x=y)
Each of the next Q lines contains two integers a and b. This query asks for the shortest distance between vertices a and b. (1≤a,b≤V)
All input values are integers, and the given graph is a 1 && 3 graph.
Print Q lines. For each query, print its answer on its own line, in the same order as the input.