atcoder#ABC301H. [ABC301Ex] Difference of Distance
[ABC301Ex] Difference of Distance
Score : points
Problem Statement
We have a connected undirected graph with vertices numbered to and edges numbered to . Edge connects vertex and vertex , and has an integer weight of . For , let us define as follows.
- For every path connecting vertex and vertex , consider the maximum weight of an edge along that path. is the minimum value of this weight.
Answer queries. The -th query is as follows.
- You are given . By what value will increase when the weight of edge is increased by ?
Note that each query does not actually change the weight of the edge.
Constraints
- The given graph is connected.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -th query.
6 6
1 2 1
3 1 5
4 1 5
3 4 3
5 6 4
2 6 5
7
1 4 6
2 4 6
3 4 6
4 4 6
5 4 6
6 4 6
5 6 5
0
0
0
0
0
1
1
The above figure shows the edge numbers in black and the edge weights in blue.
Let us explain the first through sixth queries.
First, consider in the given graph. The maximum weight of an edge along the path is , which is the minimum over all paths connecting vertex and vertex , so .
Next, consider the increment of when the weight of edge increases by . When , we have , and the increment is . On the other hand, when , we have , and the increment is . For instance, when , the maximum weight of an edge along the path is , but the maximum weight of an edge along the path $4 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 6$ is , so is still .
2 2
1 2 1
1 2 1
1
1 1 2
0
The given graph may contain multi-edges.