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"There is a tree of n vertices and a permutation p of size n . A token is present on vertex x of the tree. Alice and Bob are playing a game. Alice is in control of the permutation p , and Bob is in control of the token on the tree. In Alice's turn, she must pick two distinct numbers u and v (not positions; u neq v ), such that the token is neither at vertex u nor vertex v on the tree, and swap their positions in the permutation p . In Bob's turn, he must move the token to an adjacent vertex from the one it is currently on. Alice wants to sort the permutation in increasing order. Bob wants to prevent that. Alice wins if the permutation is sorted in increasing order at the beginning or end of her turn. Bob wins if he can make the game go on for an infinite number of moves (which means that Alice is never able to get a sorted permutation). Both players play optimally. Alice makes the first move. Given the tree, the permutation p , and the vertex x on which the token initially is, find the winner of the game. The first line contains a single integer t ( 1 <= t <= 1000 ) -- the number of test cases. The description of each test case follows. The first line of each test case has two integers n and x ( 3 <= q n <= q 2 cdot 10^5 ; 1 <= q x <= q n ). Each of the next n-1 lines contains two integers a and b ( 1 <= a, b <= n , a neq b ) indicating an undirected edge between vertex a and vertex b . It is guaranteed that the given edges form a tree. The next line contains n integers p_1, p_2, ldots, p_n ( 1 <= p_i <= n ) -- the permutation p . The sum of n over all test cases does not exceed 2 cdot 10^5 . For each test case, output one line containing Alice or Bob -- the winner of the game. The output is case-sensitive. Here is the explanation for the first example: In the first t"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
153937865 |
vlatko |
F |
April 17, 2022, 4:47 p.m. |
OK |
GNU C++17 |
TESTS |
59 |
187 |
3174400 |
|
|
153945979 |
JaroslavUrban |
F |
April 17, 2022, 6:47 p.m. |
OK |
GNU C++17 (64) |
TESTS |
59 |
93 |
2457600 |
|
|
153934308 |
MeliodasIRA |
F |
April 17, 2022, 4:32 p.m. |
OK |
GNU C++17 (64) |
TESTS |
59 |
140 |
3174400 |
|
|
153926270 |
Geothermal |
F |
April 17, 2022, 4 p.m. |
OK |
GNU C++17 (64) |
TESTS |
59 |
170 |
16281600 |
|
|
153930692 |
Mr_Eight |
F |
April 17, 2022, 4:17 p.m. |
OK |
GNU C++17 (64) |
TESTS |
59 |
202 |
11571200 |
|
|
153961278 |
DerekFeng |
F |
April 18, 2022, 1:54 a.m. |
OK |
GNU C++17 (64) |
TESTS |
59 |
390 |
23449600 |
|
|
153938221 |
Bench0310 |
F |
April 17, 2022, 4:48 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
93 |
4505600 |
|
|
153935781 |
Koosha_Mv |
F |
April 17, 2022, 4:38 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
108 |
32051200 |
|
|
153942151 |
tfg |
F |
April 17, 2022, 5:45 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
124 |
10854400 |
|
|
153940005 |
jiangly |
F |
April 17, 2022, 5:21 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
139 |
10752000 |
|
|
153959281 |
BurnedChicken |
F |
April 18, 2022, 12:42 a.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
139 |
16179200 |
|
|
153934553 |
JovanB |
F |
April 17, 2022, 4:33 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
140 |
11571200 |
|
|
153933244 |
oleh1421 |
F |
April 17, 2022, 4:27 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
140 |
11571200 |
|
|
153936898 |
tute7627 |
F |
April 17, 2022, 4:43 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
155 |
14438400 |
|
|
153945157 |
dean.menezes |
F |
April 17, 2022, 6:31 p.m. |
OK |
GNU C++20 (64) |
TESTS |
59 |
810 |
10752000 |
|
|
remove filters
Back to search problems