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 of n vertices numbered from 1 to n . A tree is a connected undirected graph without cycles. For each i=1,2, ldots, n , let w_i be the weight of the i -th vertex. A vertex is called good if its weight is equal to the sum of the weights of all its neighbors. Initially, the weights of all nodes are unassigned. Assign positive integer weights to each vertex of the tree, such that the number of good vertices in the tree is maximized. If there are multiple ways to do it, you have to find one that minimizes the sum of weights of all vertices in the tree. The first line contains one integer n ( 2 <= n <= 2 cdot 10^5 ) -- the number of vertices in the tree. Then, n xe2 x88 x921 lines follow. Each of them contains two integers u and v ( 1 <= u,v <= n ) denoting an edge between vertices u and v . It is guaranteed that the edges form a tree. In the first line print two integers -- the maximum number of good vertices and the minimum possible sum of weights for that maximum. In the second line print n integers w_1, w_2, ldots, w_n ( 1 <= w_i <= 10^9 ) -- the corresponding weight assigned to each vertex. It can be proven that there exists an optimal solution satisfying these constraints. If there are multiple optimal solutions, you may print any. This is the tree for the first test case: This is the tree for the second test case: '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
148400501 |
YOK |
D |
March 4, 2022, 9:41 p.m. |
OK |
GNU C11 |
TESTS |
67 |
873 |
11264000 |
|
2000 |
148406803 |
E-ray |
D |
March 5, 2022, 1:40 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
171 |
20787200 |
|
2000 |
148380805 |
Mercury2005 |
D |
March 4, 2022, 5:29 p.m. |
OK |
GNU C++14 |
TESTS |
67 |
217 |
23142400 |
|
2000 |
148422122 |
Himeno.Sena |
D |
March 5, 2022, 5:39 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
19353600 |
|
2000 |
148415132 |
JoesSR |
D |
March 5, 2022, 4:16 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
21504000 |
|
2000 |
148411963 |
gzchenben |
D |
March 5, 2022, 3:22 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
21913600 |
|
2000 |
148411678 |
bunny1024 |
D |
March 5, 2022, 3:17 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
22528000 |
|
2000 |
148412587 |
anmous |
D |
March 5, 2022, 3:32 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
22528000 |
|
2000 |
148387790 |
Jonothor_Darry |
D |
March 4, 2022, 6:37 p.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
23040000 |
|
2000 |
148405941 |
lplalbert111 |
D |
March 5, 2022, 1:19 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
23347200 |
|
2000 |
148409639 |
naderr |
D |
March 5, 2022, 2:38 a.m. |
OK |
GNU C++14 |
TESTS |
67 |
218 |
25702400 |
|
2000 |
148386644 |
Toby-Shi |
D |
March 4, 2022, 6:30 p.m. |
OK |
GNU C++17 |
TESTS |
67 |
171 |
21606400 |
|
2000 |
148404219 |
Pepsi__Cola |
D |
March 5, 2022, 12:20 a.m. |
OK |
GNU C++17 |
TESTS |
67 |
186 |
19968000 |
|
2000 |
148413898 |
Star_Dream |
D |
March 5, 2022, 3:55 a.m. |
OK |
GNU C++17 |
TESTS |
67 |
202 |
20992000 |
|
2000 |
148409764 |
dsrHAO |
D |
March 5, 2022, 2:40 a.m. |
OK |
GNU C++17 |
TESTS |
67 |
202 |
21811200 |
|
2000 |
148411077 |
guud222 |
D |
March 5, 2022, 3:06 a.m. |
OK |
GNU C++17 |
TESTS |
67 |
202 |
22528000 |
|
2000 |
148413141 |
han811 |
D |
March 5, 2022, 3:42 a.m. |
OK |
GNU C++17 |
TESTS |
67 |
217 |
22528000 |
|
2000 |
148393251 |
xenofil |
D |
March 4, 2022, 7:34 p.m. |
OK |
GNU C++17 |
TESTS |
67 |
217 |
24473600 |
|
2000 |
148393293 |
Eshirahh |
D |
March 4, 2022, 7:34 p.m. |
OK |
GNU C++17 |
TESTS |
67 |
217 |
24473600 |
|
2000 |
148401036 |
YuDabin |
D |
March 4, 2022, 9:54 p.m. |
OK |
GNU C++17 |
TESTS |
67 |
218 |
15462400 |
|
2000 |
148401618 |
XiaobaiWang |
D |
March 4, 2022, 10:12 p.m. |
OK |
GNU C++17 |
TESTS |
67 |
218 |
15462400 |
|
2000 |
148411507 |
niao_v |
D |
March 5, 2022, 3:14 a.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
156 |
32768000 |
|
2000 |
148411028 |
dfzgcj |
D |
March 5, 2022, 3:05 a.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
202 |
37580800 |
|
2000 |
148401003 |
Golden |
D |
March 4, 2022, 9:53 p.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
217 |
34406400 |
|
2000 |
148388301 |
sweetpotato2 |
D |
March 4, 2022, 6:41 p.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
218 |
30412800 |
|
2000 |
148402130 |
Vax |
D |
March 4, 2022, 10:29 p.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
218 |
31232000 |
|
2000 |
148379721 |
codelegend |
D |
March 4, 2022, 5:27 p.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
218 |
34406400 |
|
2000 |
148413615 |
thaizhenleng |
D |
March 5, 2022, 3:51 a.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
218 |
34713600 |
|
2000 |
148403444 |
cibernauta |
D |
March 4, 2022, 11:42 p.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
233 |
31232000 |
|
2000 |
148378711 |
Jorge213 |
D |
March 4, 2022, 5:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
233 |
31232000 |
|
2000 |
148417325 |
pavankalyanpallapolu |
D |
March 5, 2022, 4:44 a.m. |
OK |
GNU C++17 (64) |
TESTS |
67 |
233 |
34406400 |
|
2000 |
148401723 |
risujiroh |
D |
March 4, 2022, 10:15 p.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
93 |
31948800 |
|
2000 |
148419728 |
eptzd |
D |
March 5, 2022, 5:13 a.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
171 |
27238400 |
|
2000 |
148388619 |
Sui-chan_wa... |
D |
March 4, 2022, 6:43 p.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
186 |
23859200 |
|
2000 |
148411766 |
Amdadul |
D |
March 5, 2022, 3:19 a.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
186 |
37580800 |
|
2000 |
148422068 |
yangster67 |
D |
March 5, 2022, 5:38 a.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
186 |
41574400 |
|
2000 |
148408450 |
Vxlimo |
D |
March 5, 2022, 2:13 a.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
202 |
14745600 |
|
2000 |
148401012 |
_Enigma__ |
D |
March 4, 2022, 9:54 p.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
202 |
27545600 |
|
2000 |
148398734 |
A_G |
D |
March 4, 2022, 8:59 p.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
202 |
31232000 |
|
2000 |
148394521 |
jakubd |
D |
March 4, 2022, 7:49 p.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
202 |
32768000 |
|
2000 |
148389064 |
brunovsky |
D |
March 4, 2022, 6:47 p.m. |
OK |
GNU C++20 (64) |
TESTS |
67 |
202 |
34406400 |
|
2000 |
148379572 |
AndreySiunov |
D |
March 4, 2022, 5:27 p.m. |
OK |
Java 11 |
TESTS |
67 |
857 |
55398400 |
|
2000 |
148387645 |
shivakumar.nannan |
D |
March 4, 2022, 6:36 p.m. |
OK |
Java 11 |
TESTS |
67 |
1435 |
197529600 |
|
2000 |
148385542 |
Restricted |
D |
March 4, 2022, 6:24 p.m. |
OK |
Java 11 |
TESTS |
67 |
1699 |
268390400 |
|
2000 |
148403329 |
tataopop |
D |
March 4, 2022, 11:35 p.m. |
OK |
Java 11 |
TESTS |
67 |
1778 |
233779200 |
|
2000 |
148378998 |
kkkkush |
D |
March 4, 2022, 5:25 p.m. |
OK |
Java 8 |
TESTS |
67 |
1044 |
131174400 |
|
2000 |
148380172 |
golions |
D |
March 4, 2022, 5:28 p.m. |
OK |
Java 8 |
TESTS |
67 |
1653 |
218726400 |
|
2000 |
148401123 |
Rydolf_sikorski-Baal |
D |
March 4, 2022, 9:57 p.m. |
OK |
MS C++ 2017 |
TESTS |
67 |
499 |
16793600 |
|
2000 |
148392259 |
Alexey |
D |
March 4, 2022, 7:22 p.m. |
OK |
MS C++ 2017 |
TESTS |
67 |
608 |
24064000 |
|
2000 |
148385975 |
lemiao12 |
D |
March 4, 2022, 6:27 p.m. |
OK |
PyPy 3 |
TESTS |
67 |
1544 |
131072000 |
|
2000 |
148397089 |
codicon |
D |
March 4, 2022, 8:28 p.m. |
OK |
PyPy 3 |
TESTS |
67 |
1591 |
110387200 |
|
2000 |
148400210 |
akshitm16 |
D |
March 4, 2022, 9:33 p.m. |
OK |
PyPy 3 |
TESTS |
67 |
1700 |
146534400 |
|
2000 |
148400153 |
akshitm16 |
D |
March 4, 2022, 9:31 p.m. |
OK |
PyPy 3 |
TESTS |
67 |
1824 |
135475200 |
|
2000 |
148377693 |
eepsilon |
D |
March 4, 2022, 5:22 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
1169 |
74752000 |
|
2000 |
148424199 |
huikang |
D |
March 5, 2022, 5:59 a.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
1746 |
236339200 |
|
2000 |
remove filters
Back to search problems