AQT is suspicious that brainworms are running wild in DMOJistan! To limit the spread of these IQ-reducing creatures, the admins require that cities of DMOJistan quarantine for a specific amount of time.
DMOJistan can be mapped as a tree with
Constraints
For all subtasks:
For all
For all
Subtask 1 [15%]
Subtask 2 [60%]
Subtask 3 [25%]
No additional constraints.
Input Specification
The first line is a single integer
The next
The following line contains
The next
Output Specification
For each day from
Sample Input 1
5
2 3
1 3
4 2
3 5
5 5
2 2 4
4 2 5
5 3 4
5 4 5
3 1 3
Sample Output 1
2
5
5
4
3
Explanation for Sample 1
At the beginning of day 1, city 3 will form a bubble with its neighbouring cities.
At the middle of day 1, two sets are formed
At the end of day 1, nothing happens.
At the start of day 2, city 2 and 4 will form bubbles with their neighbouring cities.
At the middle of day 2, the sets are
At the end of day 2, nothing happens.
At the start of day 3, city 5 forms a bubble with its neighbouring cities.
At the middle of day 3, the sets are still
At the end of day 3, city 3 and its neighbouring cities will lift their restrictive measures.
At the start of day 4, city 5 will form another bubble with its neighbouring cities.
At the middle of day 4, the sets are
At the end of day 4, city 5 and its neighbouring cities lift their first bubble restriction but are still in quarantine from their second bubble restriction, and city 2, and its neighbouring cities, lift their quarantine restriction.
At the start of day 5, nothing happens.
At the middle of day 5, the sets are
At the end of day 5, the rest of the restrictions are lifted.
Sample Input 2
3
1 2
2 3
3 1
1 1 1
1 1 1
3 1 1
Sample Output 2
3
Explanation for Sample 2
Note that for the only day,
Comments