#P1967. [NOIP 2013 提高组] 货车运输
[NOIP 2013 提高组] 货车运输
Description
Country A has cities, numbered from to , and there are bidirectional roads between the cities. Each road has a weight limit for vehicles, referred to as the load limit.
There are trucks transporting goods. The drivers want to know, without exceeding any road's weight limit, the maximum weight each truck can carry.
Input Format
The first line contains two integers separated by a single space, indicating that Country A has cities and roads.
Each of the next lines contains three integers , separated by single spaces, indicating there is a road from city to city with weight limit .
Note: , and there may be multiple roads between two cities.
The next line contains an integer , meaning there are trucks that need to transport goods.
Then follow lines, each containing two integers separated by a space, indicating a truck needs to transport goods from city to city , with guaranteed.
Output Format
Output lines, each with an integer, indicating the maximum load for each truck.
If a truck cannot reach the destination, output .
4 3
1 2 4
2 3 3
3 1 1
3
1 3
1 4
1 3
3
-1
3
Hint
For of the testdata, , , .
For of the testdata, , , .
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号