Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B"Alice and Bob are two poachers who cut trees in a forest. A forest is a set of zero or more trees. A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a node v is the next vertex on the shortest path from v to the root. Children of vertex v are all nodes for which v is the parent. A vertex is a leaf if it has no children. In this problem we define the depth of vertex as number of vertices on the simple path from this vertex to the root. The rank of a tree is the minimum depth among its leaves. Initially there is a forest of rooted trees. Alice and Bob play a game on this forest. They play alternating turns with Alice going first. At the beginning of their turn, the player chooses a tree from the forest. Then the player chooses a positive cutting depth, which should not exceed the rank of the chosen tree. Then the player removes all vertices of that tree whose depth is less that or equal to the cutting depth. All other vertices of the tree form a set of rooted trees with root being the vertex with the smallest depth before the cut. All these trees are included in the game forest and the game continues. A player loses if the forest is empty at the beginning of his move. You are to determine whether Alice wins the game if both players play optimally. Each test contains multiple test cases. The first line contains the number of test cases t ( 1 <= q t <= q 5 cdot 10^5 ). Description of the test cases follows. The first line of each test case contains a single integer n ( 1 <= q n <= q 5 cdot 10^5 ) -- total number of vertices in the initial forest. The second line contains n integers p_1, p_2, ldots, p_n ( 0 <= q p_i <= q n ) -- description of the forest. If p_i = 0 , then the i -th vertex is the root of a tree, otherwise p_i is the parent of the vertex i . It's guaranteed that p defines a correct forest of roote"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
138988432 |
rainboy |
G |
Dec. 13, 2021, 1:28 p.m. |
OK |
GNU C++17 (64) |
TESTS |
73 |
249 |
94720000 |
|
|
138992477 |
353cerega |
G |
Dec. 13, 2021, 2:09 p.m. |
OK |
GNU C++17 (64) |
TESTS |
73 |
374 |
196403200 |
|
|
138979740 |
Andreasyan |
G |
Dec. 13, 2021, noon |
OK |
GNU C++17 (64) |
TESTS |
73 |
390 |
130969600 |
|
|
138985961 |
anakib1 |
G |
Dec. 13, 2021, 1:02 p.m. |
OK |
GNU C++20 (64) |
TESTS |
73 |
436 |
180428800 |
|
|
139018039 |
zara1234 |
G |
Dec. 13, 2021, 6:56 p.m. |
OK |
GNU C++20 (64) |
TESTS |
73 |
451 |
224563200 |
|
|
139024463 |
MAKMED1337 |
G |
Dec. 13, 2021, 8:39 p.m. |
OK |
GNU C++20 (64) |
TESTS |
73 |
623 |
176435200 |
|
|
139008244 |
NPBot |
G |
Dec. 13, 2021, 4:56 p.m. |
OK |
GNU C++20 (64) |
TESTS |
73 |
686 |
94720000 |
|
|
remove filters
Back to search problems