#abc333d. D - Erase Leaves
D - Erase Leaves
Score : points
问题描述
给定一个包含 个顶点的树:顶点 ,顶点 ,,顶点 。第 条边 连接顶点 和顶点 。
考虑重复执行以下操作若干次:
- 选择一个叶顶点 并将其及其所有相连的边一起删除。
找出删除顶点 所需的最少操作次数。
什么是树?树是一种无向图,具有连通性且不含环。更多详细信息,请参阅:维基百科 "树(图论)"。
什么是叶节点?在树中,叶是指度数不大于 的顶点。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a tree with vertices: vertex vertex , , vertex . The -th edge connects vertex and vertex .
Consider repeating the following operation some number of times:
- Choose one leaf vertex and delete it along with all incident edges.
Find the minimum number of operations required to delete vertex .
What is a tree? A tree is an undirected graph that is connected and has no cycles. For more details, see: Wikipedia "Tree (graph theory)". What is a leaf? A leaf in a tree is a vertex with a degree of at most .
Constraints
- The given graph is a tree.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in a single line.
Sample Input 1
9
1 2
2 3
2 4
2 5
1 6
6 7
7 8
7 9
Sample Output 1
5
The given graph looks like this:
For example, you can choose vertices in this order to delete vertex in five operations.
Vertex cannot be deleted in four or fewer operations, so print .
Sample Input 2
6
1 2
2 3
2 4
3 5
3 6
Sample Output 2
1
In the given graph, vertex is a leaf. Hence, you can choose and delete vertex in the first operation.
Sample Input 3
24
3 6
7 17
7 20
7 11
14 18
17 21
6 19
5 22
9 24
11 14
6 23
8 17
9 12
4 17
2 15
1 17
3 9
10 16
7 13
2 16
1 16
5 7
1 3
Sample Output 3
12
update @ 2024/3/10 01:19:42