#P8595. 「KDOI-02」一个网的路
「KDOI-02」一个网的路
Background
“{&%#~!@ovo} (They also have a road network? Interesting.)”
“{&%#@~akoio!@} (Finish the work you should do first. We will talk about those distracting toys later.)”
“{!%_&#%@yw?} (Is your Chinese language not good?)”
Under the blue sky, people still do not know that danger is coming.
Problem Description
The hostile civilization has been angered. They want to destroy Earth’s road network in a strange way. Earth’s road network can be approximated as a forest with nodes and undirected edges. They want to use the following operations:
- Destroy all roads connected outward from a city .
- Build a new road between cities .
They want to change Earth’s road network into the least efficient form: a single chain (path). Now you want to know: to achieve the goal, what is the minimum number of operations they need?
Input Format
Read input from standard input.
The first line contains positive integers .
The next lines each contain positive integers , indicating there is an undirected road between cities .
Output Format
Write output to standard output.
Output one line containing one integer, which is the minimum number of operations the aliens need.
3 1
1 2
1
见附件中的 traffic2.in
见附件中的 traffic2.ans
见附件中的 traffic3.in
见附件中的 traffic3.ans
Hint
Sample Explanation
- Sample 1 Explanation:
Initial graph:

Apply operation 2 to cities .

Now it has become a chain.
Constraints
For of the testdata, , and the input is guaranteed to be valid.
| Test Point ID | Special Property | |
|---|---|---|
| A | ||
| None | ||
| A | ||
| B | ||
| None | ||
- Special Property A: Each connected component is guaranteed to be a binary tree.
- Special Property B: The degree of each vertex is guaranteed to be at most .
Hint
This problem has a large I/O size, so a faster I/O method is recommended.
Translated by ChatGPT 5