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"Monocarp is playing a computer game where he's controlling an empire. An empire consists of n cities, connected by n - 1 roads. The cities are numbered from 1 to n . It's possible to reach every city from every other one using the roads. Traversing every road takes 2 hours. However, that can be improved. Monocarp can build railway stations in no more than k cities. After they are built, all existing roads that connect two cities with railway stations get converted to railroads and become 1 hour to traverse. Let f(x, y) be the total time it takes to traverse the roads on the shortest path between cities x and y . Monocarp wants to build at most k railway stations in such a way that the following value is minimized: sum limits_{v=1}^{n} sum limits_{u=1}^{v-1} f(v, u) (the total time it takes to travel from every city to every other one). What the smallest value he can achieve? The first line contains a single integer t ( 1 <= t <= 10^4 ) -- the number of testcases. The first line of each testcase contains two integers n and k ( 2 <= k <= n <= 2 cdot 10^5 ) -- the number of cities and the maximum number of railway stations Monocarp can build. Each of the following n-1 lines contains two integers v and u ( 1 <= v, u <= n ; v neq u ) -- a road that connects cities v and u . It's possible to reach every city from every other one using the roads. The sum of n over all testcases doesn't exceed 2 cdot 10^5 . For each testcase, print a single integer -- the smallest total time it takes to travel from every city to every other one that Monocarp can achieve after building at most k railway stations. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
236849136 |
cftauros |
F |
Dec. 12, 2023, 3:25 a.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
576 |
57241600 |
|
|
236796594 |
arvindf232 |
F |
Dec. 11, 2023, 3:05 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
702 |
71987200 |
|
|
236810189 |
MagentaCobra |
F |
Dec. 11, 2023, 4:38 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
717 |
85504000 |
|
|
236801741 |
uwi |
F |
Dec. 11, 2023, 3:37 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
935 |
121753600 |
|
|
236849024 |
cftauros |
F |
Dec. 12, 2023, 3:22 a.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
967 |
143974400 |
|
|
236802444 |
happy.potato |
F |
Dec. 11, 2023, 3:41 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
1060 |
88780800 |
|
|
236803438 |
Hakiobo |
F |
Dec. 11, 2023, 3:48 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
1107 |
94003200 |
|
|
236798831 |
pashka |
F |
Dec. 11, 2023, 3:19 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
1170 |
143257600 |
|
|
236798317 |
xiaowuc1 |
F |
Dec. 11, 2023, 3:15 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
1294 |
145817600 |
|
|
236811338 |
Jarif_Rahman |
F |
Dec. 11, 2023, 4:47 p.m. |
OK |
Kotlin 1.7 |
TESTS |
10 |
1326 |
174080000 |
|
|
236809396 |
francp22 |
F |
Dec. 11, 2023, 4:32 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1185 |
167526400 |
|
|
236802553 |
DeadlyPillow |
F |
Dec. 11, 2023, 3:42 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1247 |
152780800 |
|
|
236805426 |
thenymphsofdelphi |
F |
Dec. 11, 2023, 4:02 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1248 |
154112000 |
|
|
236806139 |
dranjohn |
F |
Dec. 11, 2023, 4:07 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1263 |
136396800 |
|
|
236797302 |
tourist |
F |
Dec. 11, 2023, 3:09 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1278 |
176947200 |
|
|
236810884 |
IsaacMoris |
F |
Dec. 11, 2023, 4:44 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1325 |
158003200 |
|
|
236806063 |
nuip |
F |
Dec. 11, 2023, 4:07 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1341 |
146944000 |
|
|
236809923 |
Darren0724 |
F |
Dec. 11, 2023, 4:36 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1357 |
150323200 |
|
|
236805459 |
Ji_Kuai |
F |
Dec. 11, 2023, 4:03 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1372 |
127795200 |
|
|
236800880 |
Kude |
F |
Dec. 11, 2023, 3:31 p.m. |
OK |
Kotlin 1.9 |
TESTS |
10 |
1387 |
171212800 |
|
|
remove filters
Back to search problems