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"Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and important order. The tree in question is a rooted tree with n vertices labelled with distinct integers from 0 to n - 1 . The vertex labelled 0 is the root of the tree, and for any non-root vertex v the label of its parent p(v) is less than the label of v . All trees at the factory are made from bamboo blanks. A bamboo is a rooted tree such that each vertex has exactly one child, except for a single leaf vertex with no children. The vertices of a bamboo blank can be labelled arbitrarily before its processing is started. To process a bamboo into another tree a single type of operation can be made: choose an arbitrary non-root vertex v such that its parent p(v) is not a root either. The operation consists of changing the parent of v to its parent's parent p(p(v)) . Note that parents of all other vertices remain unchanged, in particular, the subtree of v does not change. Efficiency is crucial, hence you have to minimize the number of operations to make the desired tree from a bamboo blank. Construct any optimal sequence of operations to produce the desired tree. Note that the labelling of the resulting tree has to coincide with the labelling of the desired tree. Formally, the labels of the roots have to be equal, and for non-root vertices with the same label the labels of their parents should be the same. It is guaranteed that for any test present in this problem an answer exists, and further, an optimal sequence contains at most 10^6 operations. Note that any hack that does not meet these conditions will be invalid. The first line contains a single integer n -- the number of vertices in the tree ( 2 <= q n <= q 10^5 ). The second line contains n - 1 integers p(1), ldots, p(n - 1)"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
63884751 |
CTP_314 |
F |
Oct. 30, 2019, 11:44 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
46 |
3788800 |
|
2500 |
64120824 |
robin12138 |
F |
Nov. 3, 2019, 1:07 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
46 |
43110400 |
|
2500 |
64120807 |
robin12138 |
F |
Nov. 3, 2019, 1:06 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
46 |
43110400 |
|
2500 |
63884736 |
CTP_314 |
F |
Oct. 30, 2019, 11:43 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
62 |
3788800 |
|
2500 |
63525653 |
wasa855 |
F |
Oct. 27, 2019, 5:10 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
62 |
11059200 |
|
2500 |
63545299 |
Frame233 |
F |
Oct. 27, 2019, 10:22 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
62 |
12288000 |
|
2500 |
66743938 |
luogu_bot2 |
F |
Dec. 12, 2019, 11:47 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
62 |
18432000 |
|
2500 |
63724108 |
LuciferX07 |
F |
Oct. 29, 2019, 12:12 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
77 |
13516800 |
|
2500 |
63963602 |
caidzh |
F |
Nov. 1, 2019, 6:18 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
77 |
18432000 |
|
2500 |
63688214 |
Dijkstra-QFJ |
F |
Oct. 29, 2019, 12:21 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
78 |
4812800 |
|
2500 |
64098706 |
BeNoble |
F |
Nov. 2, 2019, 2:44 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
31 |
7168000 |
|
2500 |
64139158 |
BeNoble |
F |
Nov. 3, 2019, 8:01 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
62 |
7168000 |
|
2500 |
64096674 |
BeNoble |
F |
Nov. 2, 2019, 2:05 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
77 |
5017600 |
|
2500 |
63557494 |
chenkuowen |
F |
Oct. 27, 2019, 1:17 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
77 |
8806400 |
|
2500 |
63549058 |
cookiedoth |
F |
Oct. 27, 2019, 11:14 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
77 |
9216000 |
|
2500 |
65791829 |
SilverLining |
F |
Nov. 26, 2019, 11:28 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
77 |
11776000 |
|
2500 |
65945771 |
bjn |
F |
Nov. 29, 2019, 8:33 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
77 |
15564800 |
|
2500 |
63520006 |
BestMSN |
F |
Oct. 27, 2019, 3:18 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
78 |
7884800 |
|
2500 |
64827194 |
busamate |
F |
Nov. 13, 2019, 3:36 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
78 |
11366400 |
|
2500 |
67281677 |
luogu_bot3 |
F |
Dec. 20, 2019, 1:14 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
93 |
5017600 |
|
2500 |
63563189 |
Ilistratov |
F |
Oct. 27, 2019, 2:58 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
77 |
10854400 |
|
2500 |
64621890 |
nikutto |
F |
Nov. 10, 2019, 7:10 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
77 |
11878400 |
|
2500 |
65556459 |
jakob_nogler |
F |
Nov. 22, 2019, 10:19 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
77 |
29593600 |
|
2500 |
63688087 |
zzpc |
F |
Oct. 29, 2019, 12:16 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
78 |
6758400 |
|
2500 |
64499734 |
bibibibi |
F |
Nov. 8, 2019, 3:20 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
78 |
7884800 |
|
2500 |
63548451 |
jiangly |
F |
Oct. 27, 2019, 11:06 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
78 |
11366400 |
|
2500 |
63542998 |
ffffxk |
F |
Oct. 27, 2019, 9:51 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
78 |
12185600 |
|
2500 |
66377523 |
interestingLSY |
F |
Dec. 6, 2019, 3:49 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
78 |
15667200 |
|
2500 |
63634761 |
Jiburiru |
F |
Oct. 28, 2019, 7:48 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
78 |
32768000 |
|
2500 |
66673266 |
sruthi_1729 |
F |
Dec. 12, 2019, 10:15 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
93 |
4198400 |
|
2500 |
63965572 |
JoelWee |
F |
Nov. 1, 2019, 7:02 a.m. |
OK |
Java 8 |
TESTS |
15 |
857 |
15257600 |
|
2500 |
remove filters
Back to search problems