#P2245. 星际导航
星际导航
Description
has prepared the hardware to return to the planet , but 's navigation system is not fully designed yet. For convenience, we can regard the universe as a weighted undirected graph with vertices and edges. Vertices represent galaxies, an edge between two galaxies means there is a direct flight between them, and the edge weight is the danger level of the voyage.
Now wants to minimize the danger level. Specifically, for several queries , wants to know the minimal possible value of the danger level of the most dangerous edge along a route from vertex to vertex . As 's classmates, you should help return home and enjoy a safe and beautiful journey through the universe. So this task is yours.
Input Format
The first line contains two positive integers and , the number of vertices and edges.
Each of the next lines contains three integers , , and , indicating that there is an edge of length between vertices and . Vertices are numbered starting from .
The next line contains a positive integer , the number of queries.
Each of the next lines contains two integers and , asking for the minimal possible value of the danger level of the most dangerous edge along any path between and .
Output Format
For each query, output the result on a separate line. If the two vertices are not reachable from each other, output .
4 5
1 2 5
1 3 2
2 3 11
2 4 6
3 4 4
3
2 3
1 4
1 2
5
4
5
Hint
For of the testdata, , , .
For of the testdata, , , .
For of the testdata, , , , . The testdata do not guarantee the absence of parallel edges and self-loops.
Translated by ChatGPT 5
京公网安备 11011102002149号