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 weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i . Let's define the k -coloring of the tree as an assignment of exactly k colors to each vertex, so that each color is used no more than two times. You can assume that you have infinitely many colors available. We say that an edge is saturated in the given k -coloring if its endpoints share at least one color (i.e. there exists a color that is assigned to both endpoints). Let's also define the value of a k -coloring as the sum of weights of saturated edges. Please calculate the maximum possible value of a k -coloring of the given tree. You have to answer q independent queries. The first line contains one integer q ( 1 <= q <= 5 cdot 10^5 ) xe2 x80 x93 the number of queries. The first line of each query contains two integers n and k ( 1 <= n, k <= 5 cdot 10^5 ) -- the number of vertices in the tree and the number of colors to assign to each vertex, respectively. Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by three integers u_i , v_i and w_i ( 1 <= u_i, v_i <= n , u_i ne v_i , 1 <= w_i <= 10^5 ) -- the labels of vertices it connects and the weight of the edge. It is guaranteed that the given edges form a tree. It is guaranteed that sum of all n over all queries does not exceed 5 cdot 10^5 . For each query print one integer -- the maximum value of a k -coloring of the given tree. The tree corresponding to the first query in the example: One of the possible k -colorings in the first example: (1), (1), (2), (2) , then the 1 -st and the 3 -rd edges are saturated and the sum of their weights is 8 . The tree corresponding to the second query in the example: One of the possible k -co"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
62100601 |
nantf |
E |
Oct. 8, 2019, 8:59 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
171 |
39628800 |
|
2200 |
62192216 |
LV24twx |
E |
Oct. 9, 2019, 10 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
171 |
43008000 |
|
2200 |
63990508 |
caidzh |
E |
Nov. 1, 2019, 1 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
171 |
47104000 |
|
2200 |
62052351 |
nantf |
E |
Oct. 7, 2019, 9:51 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
186 |
39628800 |
|
2200 |
62347584 |
AutumnKite |
E |
Oct. 11, 2019, 8:12 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
187 |
39526400 |
|
2200 |
63778296 |
Fubuki |
E |
Oct. 30, 2019, 10:15 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
187 |
42905600 |
|
2200 |
62193499 |
LV24twx |
E |
Oct. 9, 2019, 10:20 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
187 |
43110400 |
|
2200 |
64011849 |
Dream-chasing_Juvenile |
E |
Nov. 1, 2019, 3:13 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
202 |
39424000 |
|
2200 |
63989123 |
caidzh |
E |
Nov. 1, 2019, 12:36 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
202 |
47104000 |
|
2200 |
62180350 |
luogu_bot4 |
E |
Oct. 9, 2019, 6:13 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
217 |
39628800 |
|
2200 |
62681314 |
Houbunsha |
E |
Oct. 16, 2019, 12:55 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
421 |
58675200 |
|
2200 |
62185753 |
bensanhuan |
E |
Oct. 9, 2019, 8:13 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
421 |
58777600 |
|
2200 |
65326604 |
Sortoite |
E |
Nov. 19, 2019, 2:06 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
436 |
46796800 |
|
2200 |
64157179 |
LanrTabe |
E |
Nov. 3, 2019, 1:12 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
451 |
46796800 |
|
2200 |
62068406 |
lfw |
E |
Oct. 7, 2019, 3:56 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
483 |
47923200 |
|
2200 |
63753598 |
bhaag_milkha |
E |
Oct. 29, 2019, 9:39 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
514 |
52428800 |
|
2200 |
62057759 |
ubaidullaev.abil |
E |
Oct. 7, 2019, 12:39 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
545 |
56627200 |
|
2200 |
62033593 |
Qu0cNguyen |
E |
Oct. 7, 2019, 2:30 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
546 |
52531200 |
|
2200 |
62033558 |
vipghn2003 |
E |
Oct. 7, 2019, 2:29 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
546 |
52531200 |
|
2200 |
64643743 |
zerotohero |
E |
Nov. 10, 2019, 2:10 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
560 |
52531200 |
|
2200 |
62170758 |
KobeDuu_ |
E |
Oct. 9, 2019, 12:29 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
373 |
43212800 |
|
2200 |
62310912 |
chenhongta0 |
E |
Oct. 10, 2019, 1:54 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
405 |
43315200 |
|
2200 |
62095735 |
Hemengjie |
E |
Oct. 8, 2019, 7:29 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
405 |
46796800 |
|
2200 |
64438256 |
2465806616 |
E |
Nov. 7, 2019, 2:43 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
405 |
50176000 |
|
2200 |
63426784 |
Foreverftip |
E |
Oct. 26, 2019, 8:03 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
405 |
50790400 |
|
2200 |
63423977 |
vjudge1 |
E |
Oct. 26, 2019, 7:17 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
405 |
50790400 |
|
2200 |
66018485 |
wish2lucky |
E |
Nov. 30, 2019, 6:27 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
405 |
53555200 |
|
2200 |
62249200 |
zyh2000 |
E |
Oct. 10, 2019, 8:37 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
420 |
48742400 |
|
2200 |
67226676 |
Usefully_XunYu |
E |
Dec. 19, 2019, 3:27 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
436 |
39628800 |
|
2200 |
62626829 |
zzyhuajuan |
E |
Oct. 15, 2019, 2:18 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
467 |
46796800 |
|
2200 |
62588985 |
norty |
E |
Oct. 14, 2019, 8:05 p.m. |
OK |
Java 8 |
TESTS |
33 |
998 |
111616000 |
|
2200 |
62016122 |
Nutella3000 |
E |
Oct. 6, 2019, 4:06 p.m. |
OK |
Java 8 |
TESTS |
33 |
1419 |
151654400 |
|
2200 |
69270813 |
beginner1010 |
E |
Jan. 21, 2020, 8:55 p.m. |
OK |
Java 8 |
TESTS |
33 |
1466 |
254566400 |
|
2200 |
63105674 |
yaoct |
E |
Oct. 22, 2019, 4:31 a.m. |
OK |
Java 8 |
TESTS |
33 |
1481 |
202752000 |
|
2200 |
62332653 |
icpc_loser |
E |
Oct. 10, 2019, 9:49 p.m. |
OK |
Java 8 |
TESTS |
33 |
1497 |
173977600 |
|
2200 |
63680790 |
its_aks_ulure |
E |
Oct. 28, 2019, 7:54 p.m. |
OK |
Java 8 |
TESTS |
33 |
1528 |
179814400 |
|
2200 |
62052898 |
satya26 |
E |
Oct. 7, 2019, 10:03 a.m. |
OK |
Java 8 |
TESTS |
33 |
1902 |
160460800 |
|
2200 |
62064323 |
AndreWiking |
E |
Oct. 7, 2019, 2:41 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
701 |
51097600 |
|
2200 |
62025793 |
AndreWiking |
E |
Oct. 6, 2019, 8:06 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
733 |
51609600 |
|
2200 |
62062142 |
AndreWiking |
E |
Oct. 7, 2019, 1:59 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
733 |
54374400 |
|
2200 |
62063404 |
AndreWiking |
E |
Oct. 7, 2019, 2:23 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
779 |
52736000 |
|
2200 |
62233017 |
index_ |
E |
Oct. 9, 2019, 9:25 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
1606 |
92979200 |
|
2200 |
62020073 |
serg3000 |
E |
Oct. 6, 2019, 4:35 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
1700 |
63590400 |
|
2200 |
64708850 |
DarisHS |
E |
Nov. 11, 2019, 5:43 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
1778 |
58368000 |
|
2200 |
remove filters
Back to search problems