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"Recently, a tree has fallen on Bob's head from the sky. The tree has n nodes. Each node u of the tree has an integer number a_u written on it. But the tree has no fixed root, as it has fallen from the sky. Bob is currently studying the tree. To add some twist, Alice proposes a game. First, Bob chooses some node r to be the root of the tree. After that, Alice chooses a node v and tells him. Bob then can pick one or more nodes from the subtree of v . His score will be the bitwise XOR of all the values written on the nodes picked by him. Bob has to find the maximum score he can achieve for the given r and v . As Bob is not a good problem-solver, he asks you to help him find the answer. Can you help him? You need to find the answers for several combinations of r and v for the same tree. Recall that a tree is a connected undirected graph without cycles. The subtree of a node u is the set of all nodes y such that the simple path from y to the root passes through u . Note that u is in the subtree of u . Each test contains multiple test cases. The first line contains the number of test cases t ( 1 <= t <= 10^5 ). The description of the test cases follows. The first line contains an integer n ( 2 <= q n <= q 2 cdot 10^5 ) -- the number of nodes of the tree. The next line contains n space-separated integers a_1, a_2, ... , a_n ( 1 <= q a_i <= q 10^9 ) -- the values written on the nodes. Each of the next n-1 lines contain two integers u and v ( 1 <= q u, v <= q n ; u neq v ), denoting there is an undirected edge between node u and node v . It is guaranteed that the given edges form a tree. The next line contains an integer q ( 1 <= q q <= q 2 cdot 10^5 ) -- the number of queries. Each of the next q lines contains two integers r and v ( 1 <= q r, v <= q n ) -- the roo"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
191602410 |
diamond_ladybug |
E |
Feb. 1, 2023, 4:32 p.m. |
OK |
GNU C++14 |
TESTS |
25 |
498 |
114688000 |
|
|
191650906 |
wsday |
E |
Feb. 2, 2023, 3:36 a.m. |
OK |
GNU C++14 |
TESTS |
25 |
499 |
40755200 |
|
|
191650886 |
wsday |
E |
Feb. 2, 2023, 3:35 a.m. |
OK |
GNU C++14 |
TESTS |
25 |
514 |
40755200 |
|
|
191647732 |
YeahPotato |
E |
Feb. 2, 2023, 2:48 a.m. |
OK |
GNU C++14 |
TESTS |
25 |
514 |
85913600 |
|
|
191593637 |
NoPotato |
E |
Feb. 1, 2023, 4:04 p.m. |
OK |
GNU C++14 |
TESTS |
25 |
514 |
85913600 |
|
|
191602130 |
zenghaowei |
E |
Feb. 1, 2023, 4:31 p.m. |
OK |
GNU C++14 |
TESTS |
25 |
561 |
28262400 |
|
|
191648837 |
wsyhb |
E |
Feb. 2, 2023, 3:04 a.m. |
OK |
GNU C++14 |
TESTS |
25 |
655 |
128819200 |
|
|
191642489 |
WyyOIer |
E |
Feb. 2, 2023, 1:18 a.m. |
OK |
GNU C++14 |
TESTS |
25 |
655 |
131686400 |
|
|
191652937 |
WyyOIer |
E |
Feb. 2, 2023, 4:07 a.m. |
OK |
GNU C++14 |
TESTS |
25 |
670 |
131686400 |
|
|
191607643 |
Liuxizai |
E |
Feb. 1, 2023, 5:24 p.m. |
OK |
GNU C++14 |
TESTS |
25 |
717 |
78233600 |
|
|
191611622 |
walk_alone |
E |
Feb. 1, 2023, 5:46 p.m. |
OK |
GNU C++17 |
TESTS |
25 |
530 |
122470400 |
|
|
191608418 |
alchemist_5 |
E |
Feb. 1, 2023, 5:28 p.m. |
OK |
GNU C++17 |
TESTS |
25 |
576 |
21094400 |
|
|
191655027 |
0x4c |
E |
Feb. 2, 2023, 4:17 a.m. |
OK |
GNU C++17 |
TESTS |
25 |
623 |
127180800 |
|
|
191640313 |
Svyat |
E |
Feb. 2, 2023, 12:35 a.m. |
OK |
GNU C++17 |
TESTS |
25 |
670 |
95232000 |
|
|
191648242 |
Reddblue |
E |
Feb. 2, 2023, 2:55 a.m. |
OK |
GNU C++17 |
TESTS |
25 |
716 |
92160000 |
|
|
191598331 |
20069763bl |
E |
Feb. 1, 2023, 4:20 p.m. |
OK |
GNU C++17 |
TESTS |
25 |
826 |
78438400 |
|
|
191646108 |
SGColin |
E |
Feb. 2, 2023, 2:20 a.m. |
OK |
GNU C++17 |
TESTS |
25 |
842 |
127385600 |
|
|
191596106 |
Meeena |
E |
Feb. 1, 2023, 4:12 p.m. |
OK |
GNU C++17 |
TESTS |
25 |
857 |
114380800 |
|
|
191644296 |
_dan13 |
E |
Feb. 2, 2023, 1:52 a.m. |
OK |
GNU C++17 |
TESTS |
25 |
857 |
118169600 |
|
|
191640152 |
Svyat |
E |
Feb. 2, 2023, 12:32 a.m. |
OK |
GNU C++17 |
TESTS |
25 |
920 |
95232000 |
|
|
191659526 |
TJ_Andeviking |
E |
Feb. 2, 2023, 5:22 a.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
358 |
129536000 |
|
|
191599842 |
luluQAQ |
E |
Feb. 1, 2023, 4:24 p.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
483 |
45056000 |
|
|
191623186 |
huangxiaohua |
E |
Feb. 1, 2023, 7:26 p.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
608 |
128716800 |
|
|
191623277 |
huangxiaohua |
E |
Feb. 1, 2023, 7:27 p.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
623 |
128716800 |
|
|
191623131 |
huangxiaohua |
E |
Feb. 1, 2023, 7:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
624 |
128716800 |
|
|
191644970 |
MoonHalo |
E |
Feb. 2, 2023, 2:02 a.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
654 |
273920000 |
|
|
191643803 |
LXH-cat |
E |
Feb. 2, 2023, 1:44 a.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
655 |
115200000 |
|
|
191608983 |
kotatsugame |
E |
Feb. 1, 2023, 5:30 p.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
685 |
86118400 |
|
|
191608678 |
akifpatel |
E |
Feb. 1, 2023, 5:29 p.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
717 |
125849600 |
|
|
191650198 |
hihihi198 |
E |
Feb. 2, 2023, 3:25 a.m. |
OK |
GNU C++17 (64) |
TESTS |
25 |
732 |
127283200 |
|
|
191648835 |
Alice114514 |
E |
Feb. 2, 2023, 3:04 a.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
467 |
28979200 |
|
|
191639915 |
Golden_lin |
E |
Feb. 2, 2023, 12:27 a.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
514 |
33689600 |
|
|
191660843 |
gzhulc |
E |
Feb. 2, 2023, 5:38 a.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
514 |
40960000 |
|
|
191622607 |
willy108 |
E |
Feb. 1, 2023, 7:20 p.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
561 |
103526400 |
|
|
191610526 |
Setsuna |
E |
Feb. 1, 2023, 5:39 p.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
561 |
129945600 |
|
|
191643809 |
Gary2005 |
E |
Feb. 2, 2023, 1:44 a.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
592 |
125644800 |
|
|
191613982 |
Jiongly |
E |
Feb. 1, 2023, 6:01 p.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
607 |
65024000 |
|
|
191640770 |
Golden_lin |
E |
Feb. 2, 2023, 12:44 a.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
608 |
108953600 |
|
|
191617283 |
Lucina |
E |
Feb. 1, 2023, 6:26 p.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
670 |
92979200 |
|
|
191607822 |
propane |
E |
Feb. 1, 2023, 5:25 p.m. |
OK |
GNU C++20 (64) |
TESTS |
25 |
670 |
108953600 |
|
|
191614077 |
misorin |
E |
Feb. 1, 2023, 6:02 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2339 |
216985600 |
|
|
191612914 |
misorin |
E |
Feb. 1, 2023, 5:54 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2371 |
218931200 |
|
|
191637674 |
BrendanSGubbins |
E |
Feb. 1, 2023, 11:25 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2511 |
246067200 |
|
|
191620163 |
misorin |
E |
Feb. 1, 2023, 6:53 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2511 |
246067200 |
|
|
191638757 |
toam |
E |
Feb. 1, 2023, 11:56 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2870 |
164966400 |
|
|
191612218 |
misorin |
E |
Feb. 1, 2023, 5:49 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2901 |
235315200 |
|
|
191610253 |
misorin |
E |
Feb. 1, 2023, 5:37 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2917 |
229376000 |
|
|
191595208 |
toam |
E |
Feb. 1, 2023, 4:09 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2932 |
164249600 |
|
|
remove filters
Back to search problems