2637. Connections between cities

单点时限: 5.0 sec

内存限制: 256 MB

After World War X, a lot of cities have been seriously damaged, and we need to rebuild those cities. However, some materials needed can only be produced in certain places. So we need to transport these materials from city to city. For most of roads had been totally destroyed during the war, there might be no path between two cities. And no circle exists in the given graph.

Now, your task comes. After giving you the condition of the roads, we want to know if there exists a path between any two cities. If the answer is yes, output the shortest path between them.

输入格式

Input consists of multiple problem instances.For each instance, first line contains three integers n, m and c, 2<=n<=10000, 0<=m<10000, 1<=c<=1000000. n represents the number of cities numbered from 1 to n. Following m lines, each line has three integers i, j and k, represent a road between city i and city j, with length k. Last c lines, two integers i, j each line, indicates a query of city i and city j.

输出格式

For each problem instance, one line for each query. If no path between two cities, output “Not connected”, otherwise output the length of the shortest path between them.

Hint

Huge input, scanf recommended.

样例

Input
5 3 2
1 3 2
2 4 3
5 2 3
1 4
4 5
Output
Not connected
6

8 人解决,18 人已尝试。

16 份提交通过,共有 118 份提交。

7.6 EMB 奖励。

创建: 15 年,2 月前.

修改: 7 年,1 月前.

最后提交: 3 年,10 月前.

来源: 多校联合比赛BNU站

题目标签