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'Yasya was walking in the forest and accidentally found a tree with n vertices. A tree is a connected undirected graph with no cycles. Next to the tree, the girl found an ancient manuscript with m queries written on it. The queries can be of two types. The first type of query is described by the integer y . The weight of each edge in the tree is replaced by the bitwise exclusive OR of the weight of that edge and the integer y . The second type is described by the vertex v and the integer x . Yasya chooses a vertex u ( 1 <= u <= n , u neq v ) and mentally draws a bidirectional edge of weight x from v to u in the tree. Then Yasya finds a simple cycle in the resulting graph and calculates the bitwise exclusive OR of all the edges in it. She wants to choose a vertex u such that the calculated value is maximum. This calculated value will be the answer to the query. It can be shown that such a cycle exists and is unique under the given constraints (independent of the choice of u ). If an edge between v and u already existed, a simple cycle is the path v to u to v . Note that the second type of query is performed mentally, meaning the tree does not change in any way after it. Help Yasya answer all the queries. The first line contains an integer t ( 1 <= t <= 10^4 ) -- the number of test cases. The descriptions of the test cases follow. The first line of each test case contains two integers n , m ( 2 <= n <= 2 cdot 10^5 , 1 <= m <= 2 cdot 10^5 ) -- the number of vertices in the tree and the number of queries. The next n - 1 lines of each test case contain three integers v , u , w ( 1 <= v, u <= n , 1 <= w <= 10^9 ) -- the ends of some edge in the tree and its weight. It is guaranteed that the given set of edges forms a tree. The next m lines of each test case describe the queries: It is'... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
264084430 |
anmattroi |
G |
June 4, 2024, 5:31 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
25 |
609 |
81612800 |
|
|
264042823 |
hxano |
G |
June 3, 2024, 6:06 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
25 |
764 |
474726400 |
|
|
264074071 |
icyo |
G |
June 4, 2024, 3:09 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
25 |
781 |
368128000 |
|
|
264034647 |
black_big_cock |
G |
June 3, 2024, 5:05 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
25 |
2375 |
412979200 |
|
|
264082924 |
bbts |
G |
June 4, 2024, 5:16 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
530 |
158412800 |
|
|
264036421 |
Khronos_ |
G |
June 3, 2024, 5:15 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
546 |
166195200 |
|
|
264076733 |
PROELECTRO444 |
G |
June 4, 2024, 3:52 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
609 |
65740800 |
|
|
264081637 |
AliiSh |
G |
June 4, 2024, 5:01 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
609 |
168960000 |
|
|
264042859 |
flyingkite |
G |
June 3, 2024, 6:07 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
624 |
81612800 |
|
|
264076860 |
jdurie |
G |
June 4, 2024, 3:54 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
624 |
159334400 |
|
|
264053132 |
MagePetrus |
G |
June 3, 2024, 7:52 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
640 |
86220800 |
|
|
264076670 |
MintCat |
G |
June 4, 2024, 3:51 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
655 |
169574400 |
|
|
264039535 |
_bLIC_ |
G |
June 3, 2024, 5:37 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
656 |
81920000 |
|
|
264084891 |
Tanzim_bn |
G |
June 4, 2024, 5:36 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
25 |
656 |
83353600 |
|
|
264055499 |
yanold |
G |
June 3, 2024, 8:21 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
327 |
177971200 |
|
|
264052682 |
yanold |
G |
June 3, 2024, 7:46 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
343 |
176844800 |
|
|
264048516 |
yanold |
G |
June 3, 2024, 7 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
359 |
177971200 |
|
|
264051710 |
yanold |
G |
June 3, 2024, 7:35 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
374 |
176025600 |
|
|
264055394 |
yanold |
G |
June 3, 2024, 8:20 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
374 |
176742400 |
|
|
264069770 |
2333_ |
G |
June 4, 2024, 2:02 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
389 |
357580800 |
|
|
264048026 |
yanold |
G |
June 3, 2024, 6:55 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
421 |
227737600 |
|
|
264041687 |
yanold |
G |
June 3, 2024, 5:56 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
437 |
239718400 |
|
|
264048123 |
yanold |
G |
June 3, 2024, 6:56 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
452 |
227737600 |
|
|
264061503 |
kaido |
G |
June 3, 2024, 10:12 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
25 |
530 |
96972800 |
|
|
264044782 |
man-ray |
G |
June 3, 2024, 6:24 p.m. |
OK |
Java 21 |
TESTS |
25 |
1218 |
211763200 |
|
|
264044266 |
man-ray |
G |
June 3, 2024, 6:19 p.m. |
OK |
Java 21 |
TESTS |
25 |
1218 |
248012800 |
|
|
264044853 |
man-ray |
G |
June 3, 2024, 6:24 p.m. |
OK |
Java 21 |
TESTS |
25 |
1249 |
174592000 |
|
|
264043951 |
invincible777 |
G |
June 3, 2024, 6:16 p.m. |
OK |
Java 8 |
TESTS |
25 |
2452 |
243404800 |
|
|
264041344 |
misorin |
G |
June 3, 2024, 5:52 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
827 |
135065600 |
|
|
264035447 |
misorin |
G |
June 3, 2024, 5:09 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
968 |
238489600 |
|
|
264036448 |
mymelochan |
G |
June 3, 2024, 5:15 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
1546 |
299827200 |
|
|
264073727 |
cy171 |
G |
June 4, 2024, 3:03 a.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
1593 |
308224000 |
|
|
264032725 |
Divyanshu_81 |
G |
June 3, 2024, 4:56 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
1983 |
328396800 |
|
|
264061558 |
MassimoG |
G |
June 3, 2024, 10:13 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2062 |
228966400 |
|
|
264043962 |
titan23 |
G |
June 3, 2024, 6:16 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2265 |
141516800 |
|
|
264040911 |
AloFrut |
G |
June 3, 2024, 5:48 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2280 |
291225600 |
|
|
264040871 |
fisk |
G |
June 3, 2024, 5:48 p.m. |
OK |
PyPy 3-64 |
TESTS |
25 |
2280 |
291225600 |
|
|
264037591 |
toor |
G |
June 3, 2024, 5:22 p.m. |
OK |
Rust 2021 |
TESTS |
25 |
1233 |
149708800 |
|
|
264046234 |
M1ngXu |
G |
June 3, 2024, 6:37 p.m. |
OK |
Rust 2021 |
TESTS |
25 |
2296 |
505241600 |
|
|
remove filters
Back to search problems