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
Iris likes full binary trees. Let's define the depth of a rooted tree as the maximum number of vertices on the simple paths from some vertex to the root. A full binary tree of depth (d) is a binary tree of depth (d) with exactly (2^d - 1) vertices. Iris calls a tree a (d)-binary tree if some vertices and edges can be added to it to make it a full binary tree of depth (d). Note that any vertex can be chosen as the root of a full binary tree. Since performing operations on large trees is difficult, she defines the binary depth of a tree as the minimum (d) satisfying that the tree is (d)-binary. Specifically, if there is no integer (d \ge 1) such that the tree is (d)-binary, the binary depth of the tree is (-1). Iris now has a tree consisting of only vertex (1). She wants to add (n - 1) more vertices to form a larger tree. She will add the vertices one by one. When she adds vertex (i) ((2 \leq i \leq n)), she'll give you an integer (p_i) ((1 \leq p_i < i)), and add a new edge connecting vertices (i) and (p_i). Iris wants to ask you the binary depth of the tree formed by the first (i) vertices for each (1 \le i \le n). Can you tell her the answer? Each test consists of multiple test cases. The first line contains a single integer (t) ((1 \leq t \leq 10^4)) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer (n) ((2 \leq n \leq 5 \cdot 10^5)) — the final size of the tree. The second line of each test case contains (n - 1) integers (p_2, p_3, \ldots, p_n) ((1 \leq p_i < i)) — descriptions of all edges of the tree. It is guaranteed that the sum of (n) over all test cases does not exceed (5 \cdot 10^5). For each test case output (n) integers, (i)-th of them representing the binary depth of the tree formed by the first (i) vertices. In the first test case, the fi |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
278837642 |
liuhengxi |
E |
Aug. 30, 2024, 4:45 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
717 |
162713600 |
|
|
|
278836349 |
wzc_IOI_czw |
E |
Aug. 30, 2024, 4:40 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
999 |
114688000 |
|
|
|
278873011 |
Chenly |
E |
Aug. 31, 2024, 1:44 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
1077 |
163123200 |
|
|
|
278876177 |
Tagaki_san |
E |
Aug. 31, 2024, 2:50 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
1093 |
104448000 |
|
|
|
278883214 |
taiwanguo |
E |
Aug. 31, 2024, 4:33 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
1139 |
240332800 |
|
|
|
278840473 |
Qzarv |
E |
Aug. 30, 2024, 4:56 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
1202 |
413593600 |
|
|
|
278824405 |
Um_nik |
E |
Aug. 30, 2024, 4:02 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
1281 |
91750400 |
|
|
|
278839869 |
jinqihao2026 |
E |
Aug. 30, 2024, 4:54 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
1936 |
143052800 |
|
|
|
278882948 |
flying |
E |
Aug. 31, 2024, 4:29 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
40 |
2093 |
277299200 |
|
|
|
278851441 |
Fysty |
E |
Aug. 30, 2024, 6:39 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
655 |
101376000 |
|
|
|
278835798 |
noimi |
E |
Aug. 30, 2024, 4:38 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
656 |
71475200 |
|
|
|
278840442 |
Z-301 |
E |
Aug. 30, 2024, 4:56 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
656 |
102809600 |
|
|
|
278831348 |
maspy |
E |
Aug. 30, 2024, 4:23 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
765 |
113049600 |
|
|
|
278850820 |
Rubikun |
E |
Aug. 30, 2024, 6:33 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
874 |
102604800 |
|
|
|
278851016 |
Rubikun |
E |
Aug. 30, 2024, 6:35 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
874 |
102912000 |
|
|
|
278835421 |
EnofTaiPeople |
E |
Aug. 30, 2024, 4:37 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
890 |
262246400 |
|
|
|
278859466 |
asgcd |
E |
Aug. 30, 2024, 8:18 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
936 |
191692800 |
|
|
|
278836845 |
LJC00118 |
E |
Aug. 30, 2024, 4:42 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
937 |
105267200 |
|
|
|
278823646 |
Kevin114514 |
E |
Aug. 30, 2024, 3:59 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
40 |
968 |
251084800 |
|
|
|
278877188 |
jiangbowen |
E |
Aug. 31, 2024, 3:08 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
405 |
130560000 |
|
|
|
278874051 |
jiangbowen |
E |
Aug. 31, 2024, 2:06 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
514 |
106291200 |
|
|
|
278873445 |
jiangbowen |
E |
Aug. 31, 2024, 1:54 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
639 |
106291200 |
|
|
|
278874977 |
jiangbowen |
E |
Aug. 31, 2024, 2:26 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
687 |
108339200 |
|
|
|
278873676 |
neal |
E |
Aug. 31, 2024, 1:58 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
874 |
204185600 |
|
|
|
278872379 |
jiangbowen |
E |
Aug. 31, 2024, 1:28 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
905 |
106291200 |
|
|
|
278854038 |
RDDCCD |
E |
Aug. 30, 2024, 7:07 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
999 |
109363200 |
|
|
|
278842295 |
Dominater069 |
E |
Aug. 30, 2024, 5:03 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
999 |
125337600 |
|
|
|
278835070 |
Sugar_fan |
E |
Aug. 30, 2024, 4:36 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
1014 |
96665600 |
|
|
|
278873149 |
jiangbowen |
E |
Aug. 31, 2024, 1:47 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
40 |
1046 |
106291200 |
|
|
remove filters
Back to search problems