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'You are given a forest of k rooted trees ^{ text{ xe2 x88 x97}} . Lumberjack Timofey wants to cut down the entire forest by applying the following operation: Timofey loves bitwise operations, so he wants the bitwise OR of the sizes of the subtrees he removed to be maximum. Help him and find the maximum result he can obtain. ^{ text{ xe2 x88 x97}} A tree is a connected graph without cycles, loops, or multiple edges. In a rooted tree, a selected vertex is called a root. A forest is a collection of one or more trees. ^{ text{ xe2 x80 xa0}} The subtree of a vertex v is the set of vertices for which v lies on the shortest path from this vertex to the root, including v itself. Each test consists of multiple test cases. The first line contains an integer t ( 1 <= q t <= q 10^4 ) -- the number of test cases. Then follows the description of the test cases. The first line of each test case contains a single integer k ( 1 <= q k <= q 10^6 ) -- the number of trees in the forest. This is followed by a description of each of the k trees: The first line contains a single integer n ( 1 <= q n <= q 10^6 ) -- the size of the tree. The vertices of the tree are numbered with integers from 1 to n . The root of the tree is vertex number 1 . The second line contains n - 1 integers p_2, p_3, ldots p_n ( 1 <= q p_i < i ), where p_i -- the parent of vertex i . It is guaranteed that the sum of k and n for all sets of input data does not exceed 10^6 . For each test case, output a single integer -- the maximum result that can be obtained. In the second test case, the trees look like this: The first operation removes the entire second tree. The second operation removes vertex 4 from the first tree. The third operation removes the first tree. The result is 6|1|3 = 7 ( | denotes bitwise OR). In the third test case, the entire tree needs to be remove'... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
271325751 |
praneet1300 |
E |
July 19, 2024, 5:16 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
202 |
307200 |
|
|
271325678 |
praneet1300 |
E |
July 19, 2024, 5:15 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
202 |
307200 |
|
|
271271939 |
TrendBattles |
E |
July 18, 2024, 5:50 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
202 |
2662400 |
|
|
271324180 |
ztw___ |
E |
July 19, 2024, 4:58 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
203 |
3993600 |
|
|
271303064 |
dingduangdou |
E |
July 19, 2024, 1:04 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
203 |
3993600 |
|
|
271259019 |
Pinkyhead |
E |
July 18, 2024, 4:22 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
218 |
3993600 |
|
|
271329721 |
w1se |
E |
July 19, 2024, 5:56 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
218 |
7987200 |
|
|
271330197 |
byebye10000 |
E |
July 19, 2024, 6 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
233 |
2662400 |
|
|
271306712 |
UperFicial |
E |
July 19, 2024, 1:50 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
233 |
3993600 |
|
|
271257279 |
wwlw |
E |
July 18, 2024, 4:18 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
26 |
233 |
3993600 |
|
|
271262561 |
dumk |
E |
July 18, 2024, 4:31 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
187 |
2662400 |
|
|
271324016 |
xiaoyezi2007 |
E |
July 19, 2024, 4:56 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
187 |
3993600 |
|
|
271322856 |
asdvgy |
E |
July 19, 2024, 4:40 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271313361 |
nforget |
E |
July 19, 2024, 3 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271282253 |
Xiaobaibubai |
E |
July 18, 2024, 7:27 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271281102 |
MohammadHijaz |
E |
July 18, 2024, 7:14 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271275556 |
tilnoene |
E |
July 18, 2024, 6:19 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271267567 |
zzhrwww |
E |
July 18, 2024, 5:23 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271256708 |
MariamH |
E |
July 18, 2024, 4:16 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271256217 |
DELTARUNE |
E |
July 18, 2024, 4:15 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
26 |
202 |
0 |
|
|
271256600 |
Fortran_must_add_too |
E |
July 18, 2024, 4:16 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
93 |
10035200 |
|
|
271312544 |
atzk |
E |
July 19, 2024, 2:52 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
155 |
7782400 |
|
|
271320370 |
hyxawa |
E |
July 19, 2024, 4:09 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
156 |
0 |
|
|
271302030 |
oqmsac |
E |
July 19, 2024, 12:50 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
156 |
0 |
|
|
271268370 |
AnasMaged |
E |
July 18, 2024, 5:26 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
156 |
0 |
|
|
271313113 |
KobicGend |
E |
July 19, 2024, 2:58 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
156 |
3686400 |
|
|
271303527 |
mathwing |
E |
July 19, 2024, 1:11 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
156 |
3993600 |
|
|
271304978 |
youngr |
E |
July 19, 2024, 1:29 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
156 |
7680000 |
|
|
271306612 |
handleme |
E |
July 19, 2024, 1:49 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
156 |
7987200 |
|
|
271322358 |
hongjinjian |
E |
July 19, 2024, 4:34 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
26 |
171 |
0 |
|
|
271316273 |
Eznibuil |
E |
July 19, 2024, 3:29 a.m. |
OK |
GNU C11 |
TESTS |
26 |
156 |
102400 |
|
|
271315989 |
Eznibuil |
E |
July 19, 2024, 3:26 a.m. |
OK |
GNU C11 |
TESTS |
26 |
156 |
102400 |
|
|
271298281 |
rainboy |
E |
July 18, 2024, 11:34 p.m. |
OK |
GNU C11 |
TESTS |
26 |
156 |
102400 |
|
|
271315146 |
Eznibuil |
E |
July 19, 2024, 3:18 a.m. |
OK |
GNU C11 |
TESTS |
26 |
187 |
102400 |
|
|
271319425 |
nguyenquocthao00 |
E |
July 19, 2024, 3:59 a.m. |
OK |
Go |
TESTS |
26 |
405 |
48844800 |
|
|
271259922 |
MaxBuzz |
E |
July 18, 2024, 4:25 p.m. |
OK |
Java 21 |
TESTS |
26 |
467 |
14336000 |
|
|
271274770 |
saptarshi1729 |
E |
July 18, 2024, 6:12 p.m. |
OK |
Java 21 |
TESTS |
26 |
499 |
34406400 |
|
|
271277453 |
godxpunk |
E |
July 18, 2024, 6:35 p.m. |
OK |
Java 21 |
TESTS |
26 |
608 |
15257600 |
|
|
271326521 |
Sudip809 |
E |
July 19, 2024, 5:25 a.m. |
OK |
Java 21 |
TESTS |
26 |
812 |
108134400 |
|
|
271326357 |
Sudip809 |
E |
July 19, 2024, 5:23 a.m. |
OK |
Java 21 |
TESTS |
26 |
890 |
106803200 |
|
|
271268388 |
saptarshi1729 |
E |
July 18, 2024, 5:26 p.m. |
OK |
Java 21 |
TESTS |
26 |
937 |
135372800 |
|
|
271320252 |
PlayDate |
E |
July 19, 2024, 4:07 a.m. |
OK |
Java 21 |
TESTS |
26 |
1687 |
6553600 |
|
|
271276793 |
faresbadr316 |
E |
July 18, 2024, 6:29 p.m. |
OK |
Java 8 |
TESTS |
26 |
265 |
29900800 |
|
|
271277807 |
faresbadr316 |
E |
July 18, 2024, 6:39 p.m. |
OK |
Java 8 |
TESTS |
26 |
280 |
30003200 |
|
|
271276929 |
faresbadr316 |
E |
July 18, 2024, 6:30 p.m. |
OK |
Java 8 |
TESTS |
26 |
281 |
29900800 |
|
|
271276894 |
faresbadr316 |
E |
July 18, 2024, 6:30 p.m. |
OK |
Java 8 |
TESTS |
26 |
311 |
29900800 |
|
|
271281017 |
Yousef_Badr |
E |
July 18, 2024, 7:13 p.m. |
OK |
Java 8 |
TESTS |
26 |
312 |
29900800 |
|
|
271276997 |
faresbadr316 |
E |
July 18, 2024, 6:31 p.m. |
OK |
Java 8 |
TESTS |
26 |
312 |
29900800 |
|
|
271277023 |
faresbadr316 |
E |
July 18, 2024, 6:31 p.m. |
OK |
Java 8 |
TESTS |
26 |
312 |
30003200 |
|
|
271276661 |
faresbadr316 |
E |
July 18, 2024, 6:28 p.m. |
OK |
Java 8 |
TESTS |
26 |
327 |
29900800 |
|
|
271277853 |
faresbadr316 |
E |
July 18, 2024, 6:40 p.m. |
OK |
Java 8 |
TESTS |
26 |
342 |
29900800 |
|
|
271276826 |
faresbadr316 |
E |
July 18, 2024, 6:29 p.m. |
OK |
Java 8 |
TESTS |
26 |
343 |
29696000 |
|
|
271271892 |
shubham6105 |
E |
July 18, 2024, 5:49 p.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
217 |
31232000 |
|
|
271293903 |
RobinFromTheHood |
E |
July 18, 2024, 10:01 p.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
264 |
22937600 |
|
|
271269934 |
golomb |
E |
July 18, 2024, 5:36 p.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
265 |
16076800 |
|
|
271304113 |
mikeac |
E |
July 19, 2024, 1:18 a.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
265 |
22937600 |
|
|
271295165 |
RobinFromTheHood |
E |
July 18, 2024, 10:25 p.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
265 |
22937600 |
|
|
271329212 |
Little_Sheep_Yawn |
E |
July 19, 2024, 5:51 a.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
311 |
20377600 |
|
|
271323817 |
429d51579a491c57 |
E |
July 19, 2024, 4:53 a.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
327 |
63078400 |
|
|
271294623 |
alexwice |
E |
July 18, 2024, 10:14 p.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
327 |
114995200 |
|
|
271294780 |
RobinFromTheHood |
E |
July 18, 2024, 10:17 p.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
342 |
22937600 |
|
|
271278863 |
phungthienphuoc |
E |
July 18, 2024, 6:50 p.m. |
OK |
PyPy 3-64 |
TESTS |
26 |
343 |
29388800 |
|
|
271314738 |
Akshar_7 |
E |
July 19, 2024, 3:14 a.m. |
OK |
Python 3 |
TESTS |
26 |
1577 |
15872000 |
|
|
271262348 |
golomb |
E |
July 18, 2024, 4:31 p.m. |
OK |
Python 3 |
TESTS |
26 |
1858 |
121958400 |
|
|
271256652 |
andrey.m |
E |
July 18, 2024, 4:16 p.m. |
OK |
Rust 2021 |
TESTS |
26 |
124 |
24780800 |
|
|
271318934 |
liut |
E |
July 19, 2024, 3:54 a.m. |
OK |
Rust 2021 |
TESTS |
26 |
155 |
4300800 |
|
|
271319138 |
liut |
E |
July 19, 2024, 3:56 a.m. |
OK |
Rust 2021 |
TESTS |
26 |
171 |
0 |
|
|
271319998 |
SnowballSH |
E |
July 19, 2024, 4:05 a.m. |
OK |
Rust 2021 |
TESTS |
26 |
296 |
21504000 |
|
|
remove filters
Back to search problems