#P4228. [清华集训 2017] 榕树之心
[清华集训 2017] 榕树之心
Description
A banyan can be abstracted as a rooted tree with nodes, numbered , where node is the root. Initially, the tree has only node , and the heart is at node . After that, at each step, the tree grows a new node: specifically, a node adjacent to some currently existing node is added to the tree. Then, the heart moves one step along the simple path from the heart to the newly added node. This tree with nodes has many possible growth orders, and different orders may lead to different final positions of the heart. Now Evan and Lyra want to know: which nodes could possibly be the final resting position of the heart when the growth process ends?
For example, consider a tree of size with edges . There are three different growth orders that make the heart end at nodes , , and , respectively:
Finally ending at node :
- Grow from , the heart moves from to ,
- Grow from , the heart moves from back to ,
- Grow from , the heart moves from to .
Finally ending at node :
- Grow from , the heart moves from to ,
- Grow from , the heart moves from back to ,
- Grow from , the heart moves from to .
Finally ending at node :
- Grow from , the heart moves from to ,
- Grow from , the heart moves from back to ,
- Grow from , the heart moves from to .
We can prove that there is no growth order that makes the heart end at node .
Input Format
Read from standard input.
The first line contains two positive integers , representing the subtask identifier (in the samples ) and the number of test cases. Then follow test cases. For each test case:
- The first line contains a positive integer , the number of nodes in the tree.
- The next lines each contain two positive integers , indicating there is a tree edge between nodes numbered and . It is guaranteed that and the edges form a tree.
Output Format
Output to standard output.
If the input is not equal to , for each test case output a line containing a length- string. The -th character indicates whether node could be the final position of the heart. A means possible, and a means impossible.
If the input equals , then for each test case output a single character indicating the answer for node .
0 3
4
1 2
1 3
1 4
6
1 2
1 3
1 4
4 5
5 6
10
1 2
1 3
3 4
3 5
3 6
4 7
7 8
8 9
9 10
0111
000101
0000001010
Hint
TestPoint 1 [10 pts]
- .
TestPoint 2 [10 pts]
- . For every node except node , the degree (including its parent) is at most .
TestPoint 3 [10 pts]
- . Only output a single character indicating the answer for node , i.e., it suffices to ensure the correctness for node .
TestPoint 4 [35 pts]
- .
TestPoint 5 [35 pts]
- .
Translated by ChatGPT 5
京公网安备 11011102002149号