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 (an undirected connected acyclic graph) consisting of n vertices. You are playing a game on this tree. Initially all vertices are white. On the first turn of the game you choose one vertex and paint it black. Then on each turn you choose a white vertex adjacent (connected by an edge) to any black vertex and paint it black. Each time when you choose a vertex (even during the first turn), you gain the number of points equal to the size of the connected component consisting only of white vertices that contains the chosen vertex. The game ends when all vertices are painted black. Let's see the following example: Vertices 1 and 4 are painted black already. If you choose the vertex 2 , you will gain 4 points for the connected component consisting of vertices 2, 3, 5 and 6 . If you choose the vertex 9 , you will gain 3 points for the connected component consisting of vertices 7, 8 and 9 . Your task is to maximize the number of points you gain. The first line contains an integer n -- the number of vertices in the tree ( 2 <= n <= 2 cdot 10^5 ). Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by two integers u_i and v_i , the indices of vertices it connects ( 1 <= u_i, v_i <= n , u_i ne v_i ). It is guaranteed that the given edges form a tree. Print one integer -- the maximum number of points you gain if you will play optimally. The first example tree is shown in the problem statement. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
56659871 |
xzxxzx401 |
E |
July 7, 2019, 9:33 a.m. |
OK |
Clang++17 Diagnostics |
TESTS |
94 |
997 |
248012800 |
|
2000 |
57041503 |
rainboy |
E |
July 14, 2019, 3:40 p.m. |
OK |
GNU C11 |
TESTS |
94 |
78 |
13824000 |
|
2000 |
57796091 |
codehoney |
E |
July 26, 2019, 11:27 a.m. |
OK |
GNU C11 |
TESTS |
94 |
93 |
13824000 |
|
2000 |
56372036 |
disangan233 |
E |
July 1, 2019, 4:20 a.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
8192000 |
|
2000 |
64122100 |
Genius_Z |
E |
Nov. 3, 2019, 2:09 a.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
8192000 |
|
2000 |
64316052 |
cmwqf |
E |
Nov. 5, 2019, 2:09 p.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
8192000 |
|
2000 |
64725297 |
luogu_bot5 |
E |
Nov. 12, 2019, 6:12 a.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
8396800 |
|
2000 |
61016512 |
luogu_bot4 |
E |
Sept. 21, 2019, 1:31 p.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
10956800 |
|
2000 |
56415521 |
yzh666 |
E |
July 2, 2019, 4:17 a.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
11059200 |
|
2000 |
56342614 |
yzh666 |
E |
June 30, 2019, 4:42 p.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
11878400 |
|
2000 |
63913858 |
luogu_bot3 |
E |
Oct. 31, 2019, 9:19 a.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
13107200 |
|
2000 |
56396318 |
yuzhechuan |
E |
July 1, 2019, 2:45 p.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
13721600 |
|
2000 |
63100362 |
caidzh |
E |
Oct. 21, 2019, 11:50 p.m. |
OK |
GNU C++11 |
TESTS |
94 |
46 |
13926400 |
|
2000 |
68890403 |
emmmhjif |
E |
Jan. 16, 2020, 1:52 a.m. |
OK |
GNU C++14 |
TESTS |
94 |
108 |
13721600 |
|
2000 |
56361529 |
tokitsukaze |
E |
June 30, 2019, 7:31 p.m. |
OK |
GNU C++14 |
TESTS |
94 |
108 |
18636800 |
|
2000 |
57968257 |
vjudge5 |
E |
July 30, 2019, 4:10 a.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
7782400 |
|
2000 |
56430796 |
ziliuziliu |
E |
July 2, 2019, 11:57 a.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
10854400 |
|
2000 |
56748751 |
lfw |
E |
July 9, 2019, 11:02 a.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
14336000 |
|
2000 |
57326493 |
guagua123 |
E |
July 19, 2019, 12:21 p.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
15360000 |
|
2000 |
56507026 |
TJPUwgw |
E |
July 4, 2019, 8:51 a.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
16384000 |
|
2000 |
57151710 |
Rabbittank |
E |
July 16, 2019, 3:03 p.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
16998400 |
|
2000 |
61111836 |
1706915033 |
E |
Sept. 23, 2019, 11:33 a.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
18636800 |
|
2000 |
56367414 |
SaInsist |
E |
July 1, 2019, 12:34 a.m. |
OK |
GNU C++14 |
TESTS |
94 |
109 |
19251200 |
|
2000 |
64198108 |
vjudge1 |
E |
Nov. 4, 2019, 10:30 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
78 |
16179200 |
|
2000 |
56424605 |
chenluoluo |
E |
July 2, 2019, 8:58 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
93 |
13824000 |
|
2000 |
64565915 |
vjudge3 |
E |
Nov. 9, 2019, 7:40 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
108 |
13107200 |
|
2000 |
56536471 |
swust5120177231 |
E |
July 5, 2019, 1:23 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
109 |
7782400 |
|
2000 |
62086264 |
zzyhuajuan |
E |
Oct. 8, 2019, 2:13 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
109 |
13107200 |
|
2000 |
56875489 |
Sai_0511 |
E |
July 12, 2019, 8:08 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
109 |
13107200 |
|
2000 |
59340490 |
2005lz |
E |
Aug. 23, 2019, 7:17 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
109 |
13721600 |
|
2000 |
56697574 |
2409073406 |
E |
July 8, 2019, 7:44 a.m. |
OK |
GNU C++17 |
TESTS |
94 |
109 |
13824000 |
|
2000 |
56396111 |
Edwivv |
E |
July 1, 2019, 2:40 p.m. |
OK |
GNU C++17 |
TESTS |
94 |
109 |
13926400 |
|
2000 |
56796282 |
S-plus |
E |
July 10, 2019, 12:38 p.m. |
OK |
GNU C++17 |
TESTS |
94 |
109 |
14540800 |
|
2000 |
69546818 |
gaokeyong |
E |
Jan. 26, 2020, 3:35 a.m. |
OK |
Java 11 |
TESTS |
94 |
1232 |
179200000 |
|
2000 |
60388729 |
jenish9599 |
E |
Sept. 11, 2019, 12:31 p.m. |
OK |
Java 8 |
TESTS |
94 |
218 |
21401600 |
|
2000 |
56372746 |
StayAwayFromBitches |
E |
July 1, 2019, 4:51 a.m. |
OK |
Java 8 |
TESTS |
94 |
233 |
29696000 |
|
2000 |
56425101 |
Musin |
E |
July 2, 2019, 9:12 a.m. |
OK |
Java 8 |
TESTS |
94 |
234 |
24985600 |
|
2000 |
56425038 |
Musin |
E |
July 2, 2019, 9:10 a.m. |
OK |
Java 8 |
TESTS |
94 |
248 |
24985600 |
|
2000 |
60388310 |
jenish9599 |
E |
Sept. 11, 2019, 12:22 p.m. |
OK |
Java 8 |
TESTS |
94 |
264 |
16896000 |
|
2000 |
56361291 |
kusomushi |
E |
June 30, 2019, 7:25 p.m. |
OK |
Java 8 |
TESTS |
94 |
342 |
21606400 |
|
2000 |
63544997 |
tusharjape007 |
E |
Oct. 27, 2019, 10:18 a.m. |
OK |
Java 8 |
TESTS |
94 |
389 |
55398400 |
|
2000 |
56365057 |
bhautik_77 |
E |
June 30, 2019, 9:59 p.m. |
OK |
Java 8 |
TESTS |
94 |
389 |
59084800 |
|
2000 |
56951081 |
mTvTm |
E |
July 13, 2019, 2:12 a.m. |
OK |
Java 8 |
TESTS |
94 |
405 |
57241600 |
|
2000 |
56497421 |
mTvTm |
E |
July 4, 2019, 4:03 a.m. |
OK |
Java 8 |
TESTS |
94 |
420 |
57241600 |
|
2000 |
56342658 |
elizarov |
E |
June 30, 2019, 4:42 p.m. |
OK |
Kotlin |
TESTS |
94 |
530 |
24371200 |
|
2000 |
56531042 |
amirrr |
E |
July 4, 2019, 7:43 p.m. |
OK |
Kotlin |
TESTS |
94 |
608 |
55091200 |
|
2000 |
56877598 |
PugachAG |
E |
July 12, 2019, 8:56 a.m. |
OK |
Kotlin |
TESTS |
94 |
873 |
155545600 |
|
2000 |
57091065 |
XelMed |
E |
July 15, 2019, 10:46 a.m. |
OK |
Mono C# |
TESTS |
94 |
530 |
63078400 |
|
2000 |
56493020 |
SpinDOS |
E |
July 4, 2019, 12:27 a.m. |
OK |
Mono C# |
TESTS |
94 |
935 |
73420800 |
|
2000 |
56493076 |
SpinDOS |
E |
July 4, 2019, 12:31 a.m. |
OK |
Mono C# |
TESTS |
94 |
935 |
73523200 |
|
2000 |
56492855 |
SpinDOS |
E |
July 4, 2019, 12:15 a.m. |
OK |
Mono C# |
TESTS |
94 |
982 |
73420800 |
|
2000 |
56492756 |
SpinDOS |
E |
July 4, 2019, 12:05 a.m. |
OK |
Mono C# |
TESTS |
94 |
1247 |
73420800 |
|
2000 |
58071485 |
vjudge1 |
E |
July 31, 2019, 10:51 a.m. |
OK |
MS C++ |
TESTS |
94 |
78 |
10854400 |
|
2000 |
57131775 |
vjudge5 |
E |
July 16, 2019, 7:25 a.m. |
OK |
MS C++ |
TESTS |
94 |
93 |
10649600 |
|
2000 |
68842407 |
vjudge4 |
E |
Jan. 15, 2020, 6:16 a.m. |
OK |
MS C++ |
TESTS |
94 |
93 |
10854400 |
|
2000 |
58010791 |
vjudge4 |
E |
July 30, 2019, 3:19 p.m. |
OK |
MS C++ |
TESTS |
94 |
93 |
10854400 |
|
2000 |
58010040 |
vjudge2 |
E |
July 30, 2019, 3:17 p.m. |
OK |
MS C++ |
TESTS |
94 |
93 |
10854400 |
|
2000 |
56964782 |
vjudge2 |
E |
July 13, 2019, 7:58 a.m. |
OK |
MS C++ |
TESTS |
94 |
93 |
12697600 |
|
2000 |
58005168 |
vjudge3 |
E |
July 30, 2019, 3:03 p.m. |
OK |
MS C++ |
TESTS |
94 |
109 |
10854400 |
|
2000 |
68839863 |
vjudge5 |
E |
Jan. 15, 2020, 5:20 a.m. |
OK |
MS C++ |
TESTS |
94 |
109 |
14336000 |
|
2000 |
64304940 |
vjudge5 |
E |
Nov. 5, 2019, 11:12 a.m. |
OK |
MS C++ |
TESTS |
94 |
109 |
21196800 |
|
2000 |
68839907 |
vjudge1 |
E |
Jan. 15, 2020, 5:22 a.m. |
OK |
MS C++ |
TESTS |
94 |
124 |
14336000 |
|
2000 |
56748724 |
ouyeye |
E |
July 9, 2019, 11:01 a.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
140 |
11980800 |
|
2000 |
56697807 |
2465806616 |
E |
July 8, 2019, 7:49 a.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
140 |
14336000 |
|
2000 |
56394565 |
C20191522 |
E |
July 1, 2019, 2 p.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
187 |
13107200 |
|
2000 |
57016156 |
Sanqer |
E |
July 14, 2019, 11:43 a.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
202 |
11980800 |
|
2000 |
56632500 |
pmitkov |
E |
July 6, 2019, 5:17 p.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
202 |
12083200 |
|
2000 |
56551043 |
petko_mitkov |
E |
July 5, 2019, 9:46 a.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
217 |
12083200 |
|
2000 |
56455265 |
yinuo |
E |
July 3, 2019, 3:19 a.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
327 |
11776000 |
|
2000 |
56485554 |
Skeef79 |
E |
July 3, 2019, 6:10 p.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
358 |
13107200 |
|
2000 |
58345707 |
sjship |
E |
Aug. 5, 2019, 2:53 p.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
390 |
12492800 |
|
2000 |
69226086 |
suun |
E |
Jan. 21, 2020, 7:17 a.m. |
OK |
MS C++ 2017 |
TESTS |
94 |
390 |
13107200 |
|
2000 |
56489363 |
aberent |
E |
July 3, 2019, 8:28 p.m. |
OK |
PyPy 3 |
TESTS |
94 |
764 |
39731200 |
|
2000 |
56413740 |
pineriver |
E |
July 2, 2019, 2:48 a.m. |
OK |
PyPy 3 |
TESTS |
94 |
841 |
56627200 |
|
2000 |
56411709 |
Pokeylope |
E |
July 2, 2019, 12:46 a.m. |
OK |
PyPy 3 |
TESTS |
94 |
982 |
56934400 |
|
2000 |
56489581 |
aberent |
E |
July 3, 2019, 8:36 p.m. |
OK |
PyPy 3 |
TESTS |
94 |
1060 |
40755200 |
|
2000 |
58924202 |
Helli.code |
E |
Aug. 16, 2019, 6:35 p.m. |
OK |
Python 2 |
TESTS |
94 |
1310 |
41164800 |
|
2000 |
56441658 |
titia |
E |
July 2, 2019, 4:43 p.m. |
OK |
Python 3 |
TESTS |
94 |
1372 |
47308800 |
|
2000 |
65232208 |
wattaihei |
E |
Nov. 17, 2019, 5:38 a.m. |
OK |
Python 3 |
TESTS |
94 |
1372 |
197324800 |
|
2000 |
61057397 |
sansen |
E |
Sept. 22, 2019, 8:29 a.m. |
OK |
Rust |
TESTS |
94 |
124 |
18944000 |
|
2000 |
68296236 |
sansen |
E |
Jan. 6, 2020, 2:59 a.m. |
OK |
Rust |
TESTS |
94 |
139 |
26316800 |
|
2000 |
56341010 |
yakamoto |
E |
June 30, 2019, 4:35 p.m. |
OK |
Scala |
TESTS |
94 |
577 |
5017600 |
|
2000 |
remove filters
Back to search problems