#abc309d. D - Add One Edge
D - Add One Edge
Score : points
问题描述
我们有一个无向图,包含 个顶点和 条边。对于 ,第 条边连接顶点 和顶点 。
以下性质得到保证:
- 对于所有整数 和 满足 ,顶点 和顶点 相连。
- 对于所有整数 和 满足 ,顶点 和顶点 相连。
- 顶点 和顶点 不相连。
考虑执行以下操作恰好一次:
- 选择一个整数 ,满足 ,以及一个整数 ,满足 ,并添加一条连接顶点 和顶点 的边。
我们可以证明,在结果图中顶点 和顶点 总是相连的;设 为从顶点 到顶点 的最短路径(边的数量)长度。
找出通过添加适当边所能得到的最大可能的 值。
“相连”的定义:在一个无向图中,若两个顶点 和 存在一条从顶点 到顶点 的路径,则称这两个顶点是相连的。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have an undirected graph with vertices and edges. For , the -th edge connects vertex and vertex .
The following properties are guaranteed:
- Vertex and vertex are connected, for all integers and with .
- Vertex and vertex are connected, for all integers and with .
- Vertex and vertex are disconnected.
Consider performing the following operation exactly once:
- choose an integer with and an integer with , and add an edge connecting vertex and vertex .
We can show that vertex and vertex are always connected in the resulting graph; so let be the minimum length (number of edges) of a path between vertex and vertex .
Find the maximum possible resulting from adding an appropriate edge to add.
Definition of "connected" Two vertices and of an undirected graph are said to be connected if and only if there is a path between vertex and vertex .
Constraints
- if .
- Vertex and vertex are connected for all integers and such that .
- Vertex and vertex are connected for all integers and such that .
- Vertex and vertex are disconnected.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 4 6
1 2
2 3
4 5
4 6
1 3
6 7
Sample Output 1
5
If we set and , the operation yields , which is the maximum possible.
Sample Input 2
7 5 20
10 11
4 5
10 12
1 2
1 5
5 6
2 4
3 5
9 10
2 5
1 4
11 12
9 12
8 9
5 7
3 7
3 6
3 4
8 12
9 11
Sample Output 2
4
update @ 2024/3/10 08:46:26