#P6729. [WC2020] 有根树
[WC2020] 有根树
Description
Given a rooted tree with nodes, the nodes are numbered from , and node is the root. Xiaoming has a node set . For a node in , he defines the value as the number of nodes in the subtree of (including itself) that are contained in the set . For convenience, for nodes not in , we consider .
Next, Xiaoming needs you to choose a connected component that contains the root. Let be the number of nodes in that are contained in , and let be the maximum value among the nodes not in . If there is no node outside , then . Xiaoming wants you to minimize .
Xiaoming thinks this problem is quite simple, so he also provides operations. Each operation will insert or delete one node in the set . For the set after each operation, please output the minimum possible value of .
Input Format
The first line contains a positive integer , indicating the number of nodes.
The next lines each contain two integers , indicating an edge in the tree.
The next line contains a positive integer , indicating the number of operations.
The next lines each contain two numbers , indicating an operation. If , the operation inserts node into , and it is guaranteed that before the operation . If , the operation deletes node from , and it is guaranteed that before the operation . Initially, is empty.
Output Format
After each operation, output one line with one integer indicating the answer.
5
1 2
1 3
1 4
2 5
5
1 4
1 1
1 2
1 5
2 2
1
1
1
2
1
Hint
Sample Explanation
After the first operation, . One possible choice is , and then .
After the second operation, . One possible choice is , and then .
After the third operation, . One possible choice is , and then .
After the fourth operation, . One possible choice is , and then .
After the fifth operation, . One possible choice is , and then .
Constraints
For all test points: , , , .
| Test Point ID | Special Restriction | ||
|---|---|---|---|
| None | |||
| A | |||
| B | |||
| C | |||
| None | |||
The meanings of the symbols in the “Special Restriction” column are:
A: At any time, the size of the set does not exceed .
B: The tree is a chain, and node has degree .
C: For every node in the tree, its parent node index is smaller than itself, , and the -th operation inserts node into .
Translated by ChatGPT 5
京公网安备 11011102002149号