#P1272. 重建道路
重建道路
Description
After a terrible earthquake, people rebuilt Farmer John's ranch with barns (numbered ). Since there was no time to build extra roads, there is a unique path between any two barns. Therefore, the ranch road network forms a tree.
John wants to know how severe the damage would be in another earthquake. Some roads, once destroyed, would separate a subtree containing barns from the remaining barns. John wants to know the minimum number of such roads.
Input Format
The first line contains two integers, and .
From the second line to the -th line (i.e., lines), each line contains two integers and , indicating that node is the parent of node . The road network can be built as a tree rooted at node .
Output Format
Output a single line containing the minimum number of roads whose destruction would separate a subtree with exactly nodes.
11 6
1 2
1 3
1 4
1 5
2 6
2 7
2 8
4 9
4 10
4 11
2
Hint
Sample explanation: If roads and are destroyed, the subtree containing nodes () will be separated.
Constraints: , . It is guaranteed that the input forms a tree.
Translated by ChatGPT 5
京公网安备 11011102002149号