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 (a connected graph without cycles) with n vertices. Consider a fixed integer k . Then, the graph G_k is an undirected graph with n vertices, where an edge between vertices u and v exists if and only if the distance between vertices u and v in the given tree is at least k . For each k from 1 to n , print the number of connected components in the graph G_k . The first line contains the integer n ( 2 <= n <= 10^5 ) -- the number of vertices in the graph. Each of the next n-1 lines contains two integers u and v ( 1 <= u, v <= n ), denoting an edge between vertices u and v in the tree. It is guaranteed that these edges form a valid tree. Output n integers: the number of connected components in the graph G_k for each k from 1 to n . In the first example: If k=1 , the graph has an edge between each pair of vertices, so it has one component. If k=4 , the graph has only edges 4 <= ftrightarrow 6 and 5 <= ftrightarrow 6 , so the graph has 4 components. In the second example: when k=1 or k=2 the graph has one component. When k=3 the graph G_k splits into 3 components: one component has vertices 1 , 4 and 5 , and two more components contain one vertex each. When k=4 or k=5 each vertex is a separate component. '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
200472028 |
rainboy |
D |
April 2, 2023, 7:18 p.m. |
OK |
GNU C11 |
TESTS |
36 |
530 |
8601600 |
|
|
200497076 |
SunnyYuan |
D |
April 3, 2023, 2:42 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
93 |
3584000 |
|
|
200515612 |
2024fuqingran |
D |
April 3, 2023, 5:37 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
93 |
6656000 |
|
|
200502106 |
awolfloveapple |
D |
April 3, 2023, 4:19 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
93 |
7372800 |
|
|
200494656 |
Fall_of_Fall |
D |
April 3, 2023, 1:47 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
93 |
8294400 |
|
|
200465010 |
Rorshach |
D |
April 2, 2023, 6:11 p.m. |
OK |
GNU C++14 |
TESTS |
36 |
93 |
8396800 |
|
|
200493212 |
waterice |
D |
April 3, 2023, 1:09 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
93 |
10035200 |
|
|
200497042 |
ZzzzH777 |
D |
April 3, 2023, 2:42 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
109 |
7065600 |
|
|
200499503 |
interestingcn |
D |
April 3, 2023, 3:32 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
109 |
8294400 |
|
|
200496916 |
Cabbage03 |
D |
April 3, 2023, 2:39 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
109 |
8601600 |
|
|
200502916 |
bestzzz |
D |
April 3, 2023, 4:32 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
109 |
8601600 |
|
|
200502940 |
Z-301 |
D |
April 3, 2023, 4:32 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
62 |
9523200 |
|
|
200471689 |
sashwat_482002 |
D |
April 2, 2023, 7:14 p.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
5632000 |
|
|
200451791 |
Ocelot_666 |
D |
April 2, 2023, 4:31 p.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
6144000 |
|
|
200458688 |
shencheng_ |
D |
April 2, 2023, 5:28 p.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
6348800 |
|
|
200493934 |
SLZSM |
D |
April 3, 2023, 1:28 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
6656000 |
|
|
200493968 |
chunzhifeng |
D |
April 3, 2023, 1:28 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
6656000 |
|
|
200500085 |
Kicamon |
D |
April 3, 2023, 3:43 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
7577600 |
|
|
200493973 |
kiddy_z |
D |
April 3, 2023, 1:29 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
7577600 |
|
|
200500536 |
52xwj |
D |
April 3, 2023, 3:51 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
7577600 |
|
|
200499137 |
leyuo |
D |
April 3, 2023, 3:25 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
93 |
8601600 |
|
|
200507184 |
Aron_A_D_S |
D |
April 3, 2023, 5:19 a.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
108 |
5836800 |
|
|
200451862 |
sarveshkulkarni5 |
D |
April 2, 2023, 4:31 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
108 |
12595200 |
|
|
200482484 |
tupapa |
D |
April 2, 2023, 9:24 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
109 |
10444800 |
|
|
200480465 |
serialcomder |
D |
April 2, 2023, 8:57 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
109 |
10752000 |
|
|
200451647 |
AboAImanaI |
D |
April 2, 2023, 4:31 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
109 |
15360000 |
|
|
200460451 |
chzu_w |
D |
April 2, 2023, 5:38 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
109 |
18636800 |
|
|
200500491 |
Once_I_Liked_AGirl |
D |
April 3, 2023, 3:50 a.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
109 |
19251200 |
|
|
200467330 |
VegeDog |
D |
April 2, 2023, 6:31 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
109 |
24576000 |
|
|
200485923 |
iLLusio |
D |
April 2, 2023, 10:16 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
124 |
9830400 |
|
|
200461218 |
yh11 |
D |
April 2, 2023, 5:43 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
124 |
16691200 |
|
|
200462658 |
wronganswerr |
D |
April 2, 2023, 5:53 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
62 |
11571200 |
|
|
200456356 |
xx001 |
D |
April 2, 2023, 5:20 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
62 |
27238400 |
|
|
200460164 |
TrendBattles |
D |
April 2, 2023, 5:36 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
78 |
6860800 |
|
|
200515709 |
xinying1 |
D |
April 3, 2023, 5:39 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
78 |
6860800 |
|
|
200499502 |
eq24 |
D |
April 3, 2023, 3:32 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
78 |
7065600 |
|
|
200497968 |
ScarletS |
D |
April 3, 2023, 3:01 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
78 |
8294400 |
|
|
200498048 |
MiXmpoi |
D |
April 3, 2023, 3:03 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
78 |
29593600 |
|
|
200461935 |
-fAuLT- |
D |
April 2, 2023, 5:48 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
93 |
6553600 |
|
|
200521787 |
Master2010 |
D |
April 3, 2023, 5:51 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
93 |
6860800 |
|
|
200504965 |
GunSJ |
D |
April 3, 2023, 5:03 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
93 |
6860800 |
|
|
200457102 |
liangjiahui11 |
D |
April 2, 2023, 5:22 p.m. |
OK |
Go |
TESTS |
36 |
233 |
45363200 |
|
|
200462193 |
CutSandstone |
D |
April 2, 2023, 5:50 p.m. |
OK |
Java 11 |
TESTS |
36 |
482 |
41574400 |
|
|
200467919 |
optimus1369 |
D |
April 2, 2023, 6:37 p.m. |
OK |
Java 11 |
TESTS |
36 |
514 |
35020800 |
|
|
200471427 |
Panther369 |
D |
April 2, 2023, 7:12 p.m. |
OK |
Java 11 |
TESTS |
36 |
530 |
48947200 |
|
|
200460337 |
dzhi |
D |
April 2, 2023, 5:38 p.m. |
OK |
Java 11 |
TESTS |
36 |
576 |
37888000 |
|
|
200465779 |
Mustela_Erminea |
D |
April 2, 2023, 6:18 p.m. |
OK |
Java 17 |
TESTS |
36 |
904 |
26521600 |
|
|
200473834 |
swarup_312 |
D |
April 2, 2023, 7:38 p.m. |
OK |
Java 8 |
TESTS |
36 |
389 |
23449600 |
|
|
200452138 |
golions |
D |
April 2, 2023, 4:32 p.m. |
OK |
Java 8 |
TESTS |
36 |
483 |
22016000 |
|
|
200450514 |
NerfThis |
D |
April 2, 2023, 4:29 p.m. |
OK |
Java 8 |
TESTS |
36 |
592 |
32460800 |
|
|
200467481 |
aryankumar877 |
D |
April 2, 2023, 6:32 p.m. |
OK |
Java 8 |
TESTS |
36 |
982 |
22323200 |
|
|
200501057 |
code_heyguy |
D |
April 3, 2023, 4:01 a.m. |
OK |
Java 8 |
TESTS |
36 |
997 |
21708800 |
|
|
200477350 |
aryankumar877 |
D |
April 2, 2023, 8:21 p.m. |
OK |
Java 8 |
TESTS |
36 |
997 |
22835200 |
|
|
200477272 |
aadrito |
D |
April 2, 2023, 8:20 p.m. |
OK |
MS C++ 2017 |
TESTS |
36 |
249 |
5324800 |
|
|
200485352 |
aadrito |
D |
April 2, 2023, 10:08 p.m. |
OK |
MS C++ 2017 |
TESTS |
36 |
265 |
5324800 |
|
|
200468981 |
hxu10 |
D |
April 2, 2023, 6:48 p.m. |
OK |
PyPy 3 |
TESTS |
36 |
733 |
52224000 |
|
|
200469882 |
zouyu9631 |
D |
April 2, 2023, 6:56 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
327 |
35225600 |
|
|
200459322 |
zouyu9631 |
D |
April 2, 2023, 5:32 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
358 |
36761600 |
|
|
200461260 |
pirate0 |
D |
April 2, 2023, 5:43 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
405 |
38502400 |
|
|
200462442 |
Leocosmos |
D |
April 2, 2023, 5:51 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
421 |
36454400 |
|
|
200471638 |
Leocosmos |
D |
April 2, 2023, 7:14 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
436 |
36556800 |
|
|
200491438 |
00zijian |
D |
April 3, 2023, 12:23 a.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
467 |
43417600 |
|
|
200458772 |
lei-feng-lfss |
D |
April 2, 2023, 5:29 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
499 |
34099200 |
|
|
200471407 |
Quick-One |
D |
April 2, 2023, 7:12 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
514 |
41267200 |
|
|
200463243 |
Peacalm |
D |
April 2, 2023, 5:57 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
530 |
244428800 |
|
|
200498560 |
bpdolson |
D |
April 3, 2023, 3:14 a.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
546 |
60928000 |
|
|
200486807 |
C.H.A.R.L.I.E. |
D |
April 2, 2023, 10:32 p.m. |
OK |
Python 3 |
TESTS |
36 |
982 |
26726400 |
|
|
200483870 |
niyaznigmatul |
D |
April 2, 2023, 9:44 p.m. |
OK |
Rust 2021 |
TESTS |
36 |
93 |
15564800 |
|
|
remove filters
Back to search problems