!HDU2874 LCA
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了!HDU2874 LCA相关的知识,希望对你有一定的参考价值。
Connections between cities
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10037 Accepted Submission(s): 2405
Problem Description
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.
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
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.
Output
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.
Sample Input
5 3 2
1 3 2
2 4 3
5 2 3
1 4
4 5
Sample Output
Not connected
6
Hint
Hint
Huge input, scanf recommended.
Source
以上是关于!HDU2874 LCA的主要内容,如果未能解决你的问题,请参考以下文章
hdu2874(lca / tarjan离线 + RMQ在线)
HDU 2874 Connections between cities(LCA离线算法实现)
HDU2874 Connections between cities(并查集+倍增LCA算法求森林最短路)
[HDU2874]Connections between cities