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 tree with n vertices; its root is vertex 1 . Also there is a token, initially placed in the root. You can move the token to other vertices. Let's assume current vertex of token is v , then you make any of the following two possible moves: Consider that root is not a leaf (even if its degree is 1 ). Calculate the maximum number of different leaves you can visit during one sequence of moves. The first line contains two integers n and k ( 1 <= k < n <= 10^6 ) -- the number of vertices in the tree and the restriction on moving up, respectively. The second line contains n - 1 integers p_2, p_3, ... , p_n , where p_i is the parent of vertex i . It is guaranteed that the input represents a valid tree, rooted at 1 . Print one integer -- the maximum possible number of different leaves you can visit. The graph from the first example: One of the optimal ways is the next one: 1 rightarrow 2 rightarrow 1 rightarrow 5 rightarrow 3 rightarrow 7 rightarrow 4 rightarrow 6 . The graph from the second example: One of the optimal ways is the next one: 1 rightarrow 7 rightarrow 5 rightarrow 8 . Note that there is no way to move from 6 to 7 or 8 and vice versa. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
67614776 |
rainboy |
F |
Dec. 25, 2019, 4:47 p.m. |
OK |
GNU C11 |
TESTS |
123 |
748 |
67584000 |
|
2500 |
44525243 |
miaokehao |
F |
Oct. 19, 2018, 1:34 a.m. |
OK |
GNU C++11 |
TESTS |
123 |
233 |
35328000 |
|
2500 |
44544673 |
Even_Bao |
F |
Oct. 19, 2018, 12:59 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
234 |
43315200 |
|
2500 |
44751253 |
ReaLNero1 |
F |
Oct. 23, 2018, 8:03 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
234 |
43315200 |
|
2500 |
54415094 |
Ryochii |
F |
May 20, 2019, 12:07 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
249 |
44953600 |
|
2500 |
46680198 |
zhou2003 |
F |
Dec. 6, 2018, 11:44 a.m. |
OK |
GNU C++11 |
TESTS |
123 |
249 |
75571200 |
|
2500 |
44186632 |
Minamoto |
F |
Oct. 12, 2018, 1:23 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
264 |
55193600 |
|
2500 |
44959272 |
Captain_Paul |
F |
Oct. 27, 2018, 3:35 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
265 |
52838400 |
|
2500 |
51085139 |
Holland_Pig |
F |
March 9, 2019, 12:53 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
265 |
55193600 |
|
2500 |
45414523 |
Naruse_Shiroha |
F |
Nov. 7, 2018, 1:30 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
265 |
59904000 |
|
2500 |
45414873 |
zcyskyaa |
F |
Nov. 7, 2018, 1:42 p.m. |
OK |
GNU C++11 |
TESTS |
123 |
265 |
59904000 |
|
2500 |
44172139 |
remoon |
F |
Oct. 12, 2018, 6:35 a.m. |
OK |
GNU C++14 |
TESTS |
123 |
389 |
54784000 |
|
2500 |
44165356 |
Enzyme125 |
F |
Oct. 12, 2018, 12:47 a.m. |
OK |
GNU C++14 |
TESTS |
123 |
390 |
57139200 |
|
2500 |
45380637 |
C1ariS |
F |
Nov. 6, 2018, 2:35 p.m. |
OK |
GNU C++14 |
TESTS |
123 |
405 |
84275200 |
|
2500 |
44154530 |
alienware01 |
F |
Oct. 11, 2018, 5:40 p.m. |
OK |
GNU C++14 |
TESTS |
123 |
467 |
49766400 |
|
2500 |
44167350 |
JasonWhyBoune |
F |
Oct. 12, 2018, 2:52 a.m. |
OK |
GNU C++14 |
TESTS |
123 |
499 |
53043200 |
|
2500 |
44166633 |
JasonWhyBoune |
F |
Oct. 12, 2018, 2:13 a.m. |
OK |
GNU C++14 |
TESTS |
123 |
514 |
54169600 |
|
2500 |
44149717 |
ntwbvdbl_oe |
F |
Oct. 11, 2018, 4:41 p.m. |
OK |
GNU C++14 |
TESTS |
123 |
529 |
67276800 |
|
2500 |
66295133 |
davidberard |
F |
Dec. 5, 2019, 3:33 a.m. |
OK |
GNU C++14 |
TESTS |
123 |
529 |
102400000 |
|
2500 |
44165304 |
Enzyme125 |
F |
Oct. 12, 2018, 12:41 a.m. |
OK |
GNU C++14 |
TESTS |
123 |
530 |
56832000 |
|
2500 |
44153121 |
FanomYT |
F |
Oct. 11, 2018, 5:11 p.m. |
OK |
GNU C++14 |
TESTS |
123 |
530 |
67276800 |
|
2500 |
45504952 |
shuafen |
F |
Nov. 10, 2018, 9:56 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
483 |
63795200 |
|
2500 |
44424902 |
pkgunboat |
F |
Oct. 17, 2018, 3:22 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
514 |
53043200 |
|
2500 |
44178308 |
Qianyri |
F |
Oct. 12, 2018, 9:56 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
514 |
53350400 |
|
2500 |
51550698 |
idxcalccalc |
F |
March 20, 2019, 12:15 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
514 |
102604800 |
|
2500 |
48702990 |
zhangqingqi |
F |
Jan. 22, 2019, 4:07 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
529 |
87859200 |
|
2500 |
44167965 |
LaoZei |
F |
Oct. 12, 2018, 3:24 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
530 |
53043200 |
|
2500 |
44696858 |
yangjinhao |
F |
Oct. 22, 2018, 1:18 p.m. |
OK |
GNU C++17 |
TESTS |
123 |
530 |
86323200 |
|
2500 |
47962287 |
Lcentury |
F |
Jan. 5, 2019, 10:02 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
530 |
114380800 |
|
2500 |
44179107 |
dpkun |
F |
Oct. 12, 2018, 10:20 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
545 |
53043200 |
|
2500 |
45199668 |
Liwj |
F |
Nov. 2, 2018, 9:12 a.m. |
OK |
GNU C++17 |
TESTS |
123 |
592 |
98304000 |
|
2500 |
67996616 |
dalt |
F |
Dec. 31, 2019, 8:31 a.m. |
OK |
Java 11 |
TESTS |
123 |
1138 |
186060800 |
|
2500 |
67614774 |
Dukkha |
F |
Dec. 25, 2019, 4:47 p.m. |
OK |
Java 11 |
TESTS |
123 |
1809 |
91443200 |
|
2500 |
44158794 |
Shaykhutdinov-T-I |
F |
Oct. 11, 2018, 7:56 p.m. |
OK |
Java 8 |
TESTS |
123 |
1559 |
258150400 |
|
2500 |
44252146 |
PrakharJain |
F |
Oct. 13, 2018, 10:56 a.m. |
OK |
Java 8 |
TESTS |
123 |
2168 |
252313600 |
|
2500 |
44163826 |
stevie1024 |
F |
Oct. 11, 2018, 10:39 p.m. |
OK |
Java 8 |
TESTS |
123 |
2370 |
206028800 |
|
2500 |
44274197 |
SevenDeadlySins |
F |
Oct. 13, 2018, 8:11 p.m. |
OK |
Java 8 |
TESTS |
123 |
2870 |
164761600 |
|
2500 |
44844266 |
greenkirill |
F |
Oct. 25, 2018, 1:55 p.m. |
OK |
Mono C# |
TESTS |
123 |
1138 |
111820800 |
|
2500 |
44173478 |
omikad |
F |
Oct. 12, 2018, 7:25 a.m. |
OK |
Mono C# |
TESTS |
123 |
1684 |
110387200 |
|
2500 |
44173035 |
omikad |
F |
Oct. 12, 2018, 7:08 a.m. |
OK |
Mono C# |
TESTS |
123 |
2012 |
144179200 |
|
2500 |
67439886 |
r57shell |
F |
Dec. 22, 2019, 6:47 p.m. |
OK |
MS C++ |
TESTS |
123 |
561 |
73216000 |
|
2500 |
67437350 |
r57shell |
F |
Dec. 22, 2019, 5:44 p.m. |
OK |
MS C++ |
TESTS |
123 |
1310 |
168243200 |
|
2500 |
44148343 |
kobae964 |
F |
Oct. 11, 2018, 4:33 p.m. |
OK |
Rust |
TESTS |
123 |
873 |
266444800 |
|
2500 |
remove filters
Back to search problems