题目链接:http://cs.scu.edu.cn/soj/problem.action?id=3098
题目概述:
Description
Once again, James Bond is on his way to saving the world. Bond's latest mission requires
him to travel between several pairs of cities in a certain country.
The country has N cities (numbered by 1, 2, . . ., N), connected by M bidirectional roads.
Bond is going to steal a vehicle, and drive along the roads from city s to city t.
The country's police will be patrolling the roads, looking for Bond, however, not all
roads get the same degree of attention from the police.
More formally, for each road MI6 has estimated its dangerousness, the higher it is,
the more likely Bond is going to be caught while driving on this road. Dangerousness
of a path from s to t is defined as the maximum dangerousness of any road on this path.
Now, it's your job to help Bond succeed in saving the world by finding the least dangerous
paths for his mission.
Input
There will be at most 5 cases in the input file.
The first line of each case contains two integers N, M (2 ≤ N≤ 50000, 1≤ M ≤ 100000) –
number of cities and roads. The next M lines describe the roads. The i-th of these lines
contains three integers: xi, yi, di (1 ≤ xi, yi ≤ N, 0 ≤ di ≤ 10^9) - the numbers of the
cities connected by the ith road and its dangerousness.
Description of the roads is followed by a line containing an integer Q (1 ≤ Q ≤ 50000), followed
by Q lines, the i-th of which contains two integers si and ti (1 ≤ si, ti ≤ N, si != ti).
Consecutive input sets are separated by a blank line.
Output
For each case, output Q lines, the i-th of which contains the minimum dangerousness of a path
between cities si and ti. Consecutive output blocks are separated by a blank line.
The input file will be such that there will always be at least one valid path.
Sample Input
4 5
1 2 10
1 3 20
1 4 100
2 4 30
3 4 10
2
1 4
4 1
2 1
1 2 100
1
1 2
Sample Output
20
20
100
Source
Ivan Krasilnikov @ Next generation contest – 4 @ UVA
解决方案:最小生成树+lca(可以用tarjan,正是因为我想用rmq结果搞得fuckable了)
代码: