Codeforces Round 975 (Div. 1)

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.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
2018 Codeforces Round 975 (Div. 1) FINISHED False 9000 48961523 Sept. 27, 2024, 1:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 9526 ) C Tree Pruning PROGRAMMING brute force data structures dfs and similar greedy sortings trees

You are given a tree with (n) nodes, rooted at node (1). In this problem, a leaf is a non-root node with degree (1). In one operation, you can remove a leaf and the edge adjacent to it (possibly, new leaves appear). What is the minimum number of operations that you have to perform to get a tree, also rooted at node (1), where all the leaves are at the same distance from the root? Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains a single integer (n) ((3 \leq n \leq 5 \cdot 10^5)) — the number of nodes. Each of the next (n-1) lines contains two integers (u), (v) ((1 \leq u, v \leq n), (u \neq v)), describing an edge that connects (u) and (v). It is guaranteed that the given edges form a tree. It is guaranteed that the sum of (n) over all test cases does not exceed (5 \cdot 10^5). For each test case, output a single integer: the minimum number of operations needed to achieve your goal. In the first two examples, the tree is as follows: In the first example, by removing edges ((1, 3)) and ((2, 5)), the resulting tree has all leaves (nodes (6) and (7)) at the same distance from the root (node (1)), which is (3). The answer is (2), as it is the minimum number of edges that need to be removed to achieve the goal. In the second example, removing edges ((1, 4)) and ((5, 7)) results in a tree where all leaves (nodes (4) and (5)) are at the same distance from the root (node (1)), which is (2).

Tutorials

Editorial of Codeforces Round 975 (Div. 1, Div. 2)

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
283215327 wcdr C Sept. 27, 2024, 2:32 p.m. OK C++17 (GCC 7-32) TESTS 16 187 18329600
283313533 zzfzzfzzfs C Sept. 28, 2024, 5:38 a.m. OK C++17 (GCC 7-32) TESTS 16 343 21913600
283212552 zhenghanyun3 C Sept. 27, 2024, 2:27 p.m. OK C++17 (GCC 7-32) TESTS 16 374 18124800
283195159 hzt1 C Sept. 27, 2024, 1:54 p.m. OK C++17 (GCC 7-32) TESTS 16 374 38502400
283196810 runzelai C Sept. 27, 2024, 1:57 p.m. OK C++17 (GCC 7-32) TESTS 16 390 23654400
283220555 Marco_L_T C Sept. 27, 2024, 2:44 p.m. OK C++17 (GCC 7-32) TESTS 16 421 18432000
283197234 SW_Wind C Sept. 27, 2024, 1:57 p.m. OK C++17 (GCC 7-32) TESTS 16 421 18534400
283217859 cmdgbb C Sept. 27, 2024, 2:38 p.m. OK C++17 (GCC 7-32) TESTS 16 421 26419200
283307172 Yoralen C Sept. 28, 2024, 4:37 a.m. OK C++17 (GCC 7-32) TESTS 16 421 32870400
283205858 KroosTheKeenGlint C Sept. 27, 2024, 2:13 p.m. OK C++17 (GCC 7-32) TESTS 16 436 28467200
283219338 xu826281112 C Sept. 27, 2024, 2:42 p.m. OK C++20 (GCC 13-64) TESTS 16 249 62156800
283209028 noya2 C Sept. 27, 2024, 2:19 p.m. OK C++20 (GCC 13-64) TESTS 16 312 43417600
283238230 fried-chicken_fan C Sept. 27, 2024, 3:27 p.m. OK C++20 (GCC 13-64) TESTS 16 358 63488000
283217447 interlude C Sept. 27, 2024, 2:37 p.m. OK C++20 (GCC 13-64) TESTS 16 359 34611200
283220879 yangsonghan C Sept. 27, 2024, 2:45 p.m. OK C++20 (GCC 13-64) TESTS 16 359 38502400
283217851 KevinLikesCoding C Sept. 27, 2024, 2:38 p.m. OK C++20 (GCC 13-64) TESTS 16 374 50073600
283223506 oyzr C Sept. 27, 2024, 2:51 p.m. OK C++20 (GCC 13-64) TESTS 16 374 51404800
283267677 dapingguo8 C Sept. 27, 2024, 6 p.m. OK C++20 (GCC 13-64) TESTS 16 374 70963200
283197789 xuanxuan001 C Sept. 27, 2024, 1:58 p.m. OK C++20 (GCC 13-64) TESTS 16 389 35737600
283269118 jxjxjx C Sept. 27, 2024, 6:11 p.m. OK C++20 (GCC 13-64) TESTS 16 406 117964800
283310933 honghaojin C Sept. 28, 2024, 5:15 a.m. OK C++23 (GCC 14-64, msys2) TESTS 16 467 60313600
283217968 SSL_TJH C Sept. 27, 2024, 2:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 16 514 50073600
283305464 Srginit286 C Sept. 28, 2024, 4:16 a.m. OK C++23 (GCC 14-64, msys2) TESTS 16 530 50380800
283284755 Zbyszek99 C Sept. 27, 2024, 9:20 p.m. OK C++23 (GCC 14-64, msys2) TESTS 16 531 41164800
283292263 Benq C Sept. 28, 2024, 12:34 a.m. OK C++23 (GCC 14-64, msys2) TESTS 16 546 47616000
283218811 Richard1211 C Sept. 27, 2024, 2:40 p.m. OK C++23 (GCC 14-64, msys2) TESTS 16 546 72499200
283192407 tatyam C Sept. 27, 2024, 1:50 p.m. OK C++23 (GCC 14-64, msys2) TESTS 16 592 48640000
283299285 kfgzsdd C Sept. 28, 2024, 2:52 a.m. OK C++23 (GCC 14-64, msys2) TESTS 16 592 56524800
283236856 askd C Sept. 27, 2024, 3:23 p.m. OK C++23 (GCC 14-64, msys2) TESTS 16 593 35328000
283222100 MAKMED1337 C Sept. 27, 2024, 2:48 p.m. OK C++23 (GCC 14-64, msys2) TESTS 16 593 38912000
283211718 KumaTachiRen C Sept. 27, 2024, 2:25 p.m. OK C# 8 TESTS 16 1217 114278400
283213230 Gassa C Sept. 27, 2024, 2:28 p.m. OK D TESTS 16 983 45363200
283257763 rainboy C Sept. 27, 2024, 4:53 p.m. OK GNU C11 TESTS 16 468 34918400
283202794 -dub-otrezkov- C Sept. 27, 2024, 2:07 p.m. OK Go TESTS 16 921 110489600
283277780 Utsav82 C Sept. 27, 2024, 7:38 p.m. OK Java 21 TESTS 16 1312 144896000
283225383 DarLam C Sept. 27, 2024, 2:56 p.m. OK Java 21 TESTS 16 1936 92160000
283196294 arvindf232 C Sept. 27, 2024, 1:56 p.m. OK Kotlin 1.9 TESTS 16 499 29900800
283204243 Tlatoani C Sept. 27, 2024, 2:10 p.m. OK Kotlin 1.9 TESTS 16 1296 95232000
283201873 bcollet C Sept. 27, 2024, 2:05 p.m. OK PyPy 2 TESTS 16 1249 75161600
283212484 misorin C Sept. 27, 2024, 2:26 p.m. OK PyPy 3-64 TESTS 16 953 76083200
283224801 yupooh C Sept. 27, 2024, 2:54 p.m. OK PyPy 3-64 TESTS 16 1499 127385600
283198451 chinerist C Sept. 27, 2024, 1:59 p.m. OK PyPy 3-64 TESTS 16 1624 128921600
283228043 eepsilon C Sept. 27, 2024, 3:02 p.m. OK PyPy 3-64 TESTS 16 1655 126054400
283219302 Mukundan314 C Sept. 27, 2024, 2:42 p.m. OK PyPy 3-64 TESTS 16 1671 135782400
283234097 flygon C Sept. 27, 2024, 3:16 p.m. OK PyPy 3-64 TESTS 16 1702 156364800
283211648 dyppp C Sept. 27, 2024, 2:25 p.m. OK PyPy 3-64 TESTS 16 1749 136089600
283222499 hxu10 C Sept. 27, 2024, 2:49 p.m. OK PyPy 3-64 TESTS 16 1812 163225600
283213762 tassei903 C Sept. 27, 2024, 2:29 p.m. OK PyPy 3-64 TESTS 16 1875 164352000
283245046 fatalerror C Sept. 27, 2024, 3:44 p.m. OK PyPy 3-64 TESTS 16 2031 171417600
283294688 Spheniscine C Sept. 28, 2024, 1:35 a.m. OK Rust 2021 TESTS 16 499 51916800
283248089 PugachAG C Sept. 27, 2024, 3:52 p.m. OK Rust 2021 TESTS 16 499 100044800
283199965 sansen C Sept. 27, 2024, 2:02 p.m. OK Rust 2021 TESTS 16 515 80588800
283229754 Nullptrs C Sept. 27, 2024, 3:06 p.m. OK Rust 2021 TESTS 16 562 85811200
283193718 Egor C Sept. 27, 2024, 1:52 p.m. OK Rust 2021 TESTS 16 624 139878400

remove filters

Back to search problems