#abc301h. Ex - Difference of Distance
Ex - Difference of Distance
Score : points
问题描述
我们有一个包含 个顶点的连通无向图,顶点编号从 到 ,并有 条边,编号从 到 。第 条边连接顶点 和顶点 ,具有整数权重 。对于 且 ,让我们定义 如下:
- 对于每条连接顶点 和顶点 的路径,考虑该路径上最大边权重。 是这个权重的最小值。
解答 个查询。第 个查询如下:
- 给定 ,当边 的权重增加 时, 将增加多少?
注意:每个查询实际上并不会改变边的权重。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
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
Sample Output 1
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 .
Sample Input 2
2 2
1 2 1
1 2 1
1
1 1 2
Sample Output 2
0
The given graph may contain multi-edges.
update @ 2024/3/10 08:28:28