Problem K. Connections between cities
时间限制 5000 ms
内存限制 32 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, no circle exists as well.
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.
输入数据
输出数据
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.
样例输入
复制
5 3 2
1 3 2
2 4 3
5 2 3
1 4
4 5
样例输出
样例说明
Hint Huge input, scanf recommended.
$ Mathjax font initiator $