#P2245. 星际导航

星际导航

Description

sideman\text{sideman} has prepared the hardware to return to the planet Gliese\text{Gliese}, but sideman\text{sideman}'s navigation system is not fully designed yet. For convenience, we can regard the universe as a weighted undirected graph with NN vertices and MM 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 sideman\text{sideman} wants to minimize the danger level. Specifically, for several queries (A,B)(A, B), sideman\text{sideman} wants to know the minimal possible value of the danger level of the most dangerous edge along a route from vertex AA to vertex BB. As sideman\text{sideman}'s classmates, you should help sideman\text{sideman} 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 NN and MM, the number of vertices and edges.

Each of the next MM lines contains three integers AA, BB, and LL, indicating that there is an edge of length LL between vertices AA and BB. Vertices are numbered starting from 11.

The next line contains a positive integer QQ, the number of queries.

Each of the next QQ lines contains two integers AA and BB, asking for the minimal possible value of the danger level of the most dangerous edge along any path between AA and BB.

Output Format

For each query, output the result on a separate line. If the two vertices are not reachable from each other, output impossible\text{impossible}.

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 40%40\% of the testdata, N1000N \leq 1000, M3000M \leq 3000, Q1000Q \leq 1000.

For 80%80\% of the testdata, N10000N \leq 10000, M105M \leq 10^5, Q1000Q \leq 1000.

For 100%100\% of the testdata, N105N \leq 10^5, M3×105M \leq 3 \times 10^5, Q105Q \leq 10^5, L109L \leq 10^9. The testdata do not guarantee the absence of parallel edges and self-loops.

Translated by ChatGPT 5