#P9175. [COCI 2022/2023 #4] Mreža
[COCI 2022/2023 #4] Mreža
Background
Account suspension due to “carding” in the judge.
Problem Description
Mayor Mirko lives in a city with neighborhoods. These neighborhoods are connected by two-way roads, and from any neighborhood you can reach any other neighborhood.
Mirko wants to upgrade some roads to ease traffic. For each road, we know the current driving speed on this road, the upgrade cost , and the driving speed after upgrading.
There are unhappy citizens who come to see Mirko. Each of them has their own upgrade suggestion. The -th citizen suggests: “We should invest euros to upgrade the roads on the route between neighborhoods and .”
For each suggestion, Mirko is interested in the following: if his goal is to maximize the minimum driving speed between neighborhoods and , then what is that minimum driving speed when he can spend at most euros on upgrading roads.
Mirko immediately realizes that this problem is not simple, so he hires you to help him.
Input Format
The first line contains an integer , the total number of neighborhoods.
The next lines each contain five integers $x_i,y_i,v_i,c_i,s_i\ (1\le x_i,y_i\le n,1\le v_i<s_i\le 10^9,1\le c_i\le 10^9)$, meaning there is a road between neighborhoods and . The current driving speed on this road is , the upgrade cost is , and the driving speed after upgrading is .
The next line contains an integer , the total number of unhappy citizens.
The next lines each contain three integers $a_i,b_i,e_i\ (1\le a_i,b_i\le n,a_i\neq b_i,1\le e_i\le 10^{18})$, with the meaning as described above.
Output Format
Output lines, where each line is the answer for the corresponding citizen’s suggestion.
6
1 2 5 7 10
1 3 4 8 9
3 4 7 1 15
3 5 6 3 11
3 6 5 6 8
3
2 4 15
6 4 5
3 5 10
7
5
11
4
1 2 5 5 8
2 3 4 6 9
3 4 6 10 7
4
1 4 16
2 4 16
1 4 10
3 4 10
6
7
5
7
Hint
Sample explanation : The figure below shows the city and the neighborhoods. On each edge, the numbers are the current driving speed, the upgrade cost, and the driving speed after upgrading.

If we upgrade the roads between and , and between and , then the driving speeds from to will become . The minimum is .
If we upgrade the road between and , then the driving speeds from to will become . The minimum is .
If we upgrade the road between and , then the driving speed from to will become .
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| Sample only | ||
| Each neighborhood is connected to at most two other neighborhoods | ||
| No additional constraints |
Translated by ChatGPT 5