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 |
|---|---|---|---|---|---|---|
| 2183 | Hello 2026 | FINISHED | False | 10800 | 8609123 | Jan. 7, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 2480 ) | D2 | Tree Coloring (Hard Version) | PROGRAMMING | constructive algorithms data structures dfs and similar greedy implementation trees |
This is the Hard version of the problem. The difference between the versions is that in this version, you must find the minimum number of operations and find a way to color the tree using that many operations. You can hack only if you solved all versions of this problem. You are given a rooted tree(^{\text{∗}}) consisting of (n) vertices numbered from (1) to (n), where the root has index (1), and each vertex is initially white. Define (d_i) as the distance from the root to the (i)-th vertex. You can perform the following operations any number of times: Select a subset (S) of white vertices such that no two nodes in (S) are connected by an edge, or have the same distance to node (1). Formally, (S) should satisfy for all (x,y\in S) and (x\neq y), (d_x\neq d_y), and there are no edges between (x) and (y). Color the vertices in (S) black. Your job is to find the minimum number of operations required to color the full tree black and find a way to perform the operations . (^{\text{∗}})A tree is a connected graph without cycles. A rooted tree is a tree where one vertex is special and called 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) ((2\le n\le 2\cdot 10^5)) – the number of vertices in the tree. The (i)-th following (n-1) lines contain two integers (u_i) and (v_i) ((1\le u_i,v_i\le n), (u_i\neq v_i)) — the ends of the (i)-th edge. It is guaranteed that the given edges form a tree. It is guaranteed that the sum of (n) over all test cases doesn't exceed (2\cdot10^5). For each test case: Output your number of operations (k) on the first line ((1 \leq k \leq n)). Then, output (k) lines. Each line should begin with an integer (m) representing the |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 356855095 | AnatolyTolstobrov | D2 | Jan. 7, 2026, 5:02 p.m. | OK | C# 10 | TESTS | 30 | 468 | 83251200 | ||
| 356854453 | suryatej_69 | D2 | Jan. 7, 2026, 5 p.m. | OK | C# 10 | TESTS | 30 | 609 | 65843200 | ||
| 356898038 | MinhKien | D2 | Jan. 8, 2026, 3:52 a.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 250 | 23859200 | ||
| 356856572 | CrossFire1 | D2 | Jan. 7, 2026, 5:06 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 265 | 6451200 | ||
| 356863010 | beckhamwee46 | D2 | Jan. 7, 2026, 5:26 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 265 | 13516800 | ||
| 356863256 | JATINBHATIA | D2 | Jan. 7, 2026, 5:26 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 265 | 15462400 | ||
| 356860538 | omar_faruk_fahim | D2 | Jan. 7, 2026, 5:18 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 265 | 16281600 | ||
| 356861698 | imarn | D2 | Jan. 7, 2026, 5:22 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 265 | 20480000 | ||
| 356861102 | klusha31 | D2 | Jan. 7, 2026, 5:20 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 281 | 15564800 | ||
| 356849976 | govind51n9h | D2 | Jan. 7, 2026, 4:47 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 281 | 15564800 | ||
| 356858111 | darsh_sodani007 | D2 | Jan. 7, 2026, 5:11 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 281 | 15667200 | ||
| 356850120 | Muhammad-Saim | D2 | Jan. 7, 2026, 4:48 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 281 | 15872000 | ||
| 356862524 | 1234567st | D2 | Jan. 7, 2026, 5:24 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 218 | 49868800 | ||
| 356865452 | mady9613 | D2 | Jan. 7, 2026, 5:32 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 20275200 | ||
| 356856235 | Godelian | D2 | Jan. 7, 2026, 5:05 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 20992000 | ||
| 356861432 | Eskoqrutz | D2 | Jan. 7, 2026, 5:21 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 24371200 | ||
| 356889785 | lhy123 | D2 | Jan. 8, 2026, 1:03 a.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 28774400 | ||
| 356865757 | Hosen_ba | D2 | Jan. 7, 2026, 5:33 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 41676800 | ||
| 356890618 | cdx123456 | D2 | Jan. 8, 2026, 1:32 a.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 50380800 | ||
| 356857372 | rogachkovdenis | D2 | Jan. 7, 2026, 5:09 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 54169600 | ||
| 356887260 | mhmusanna | D2 | Jan. 7, 2026, 11:27 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 56320000 | ||
| 356886846 | El_Farag | D2 | Jan. 7, 2026, 11:11 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 58163200 | ||
| 356893471 | csp1025 | D2 | Jan. 8, 2026, 2:37 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 203 | 49664000 | ||
| 356881110 | rgnerdplayer | D2 | Jan. 7, 2026, 8:45 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 218 | 45772800 | ||
| 356887341 | scorpion | D2 | Jan. 7, 2026, 11:31 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 234 | 22016000 | ||
| 356862615 | ibhushani | D2 | Jan. 7, 2026, 5:24 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 19148800 | ||
| 356879151 | astroanonymous | D2 | Jan. 7, 2026, 8:15 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 19558400 | ||
| 356882814 | FzArK | D2 | Jan. 7, 2026, 9:16 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 19660800 | ||
| 356857072 | vignesh_1324 | D2 | Jan. 7, 2026, 5:08 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 20070400 | ||
| 356850776 | ashwini_doesnt_code | D2 | Jan. 7, 2026, 4:50 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 22835200 | ||
| 356890406 | MEDAAA | D2 | Jan. 8, 2026, 1:25 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 26009600 | ||
| 356906138 | NigthMare21 | D2 | Jan. 8, 2026, 5:39 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 29184000 | ||
| 356866077 | Gassa | D2 | Jan. 7, 2026, 5:34 p.m. | OK | D | TESTS | 30 | 1031 | 92979200 | ||
| 356858897 | pengin_2000 | D2 | Jan. 7, 2026, 5:13 p.m. | OK | GNU C11 | TESTS | 30 | 781 | 17612800 | ||
| 356878413 | beatinghu | D2 | Jan. 7, 2026, 8:04 p.m. | OK | Java 21 | TESTS | 30 | 281 | 7884800 | ||
| 356863605 | jitendrakumaryadav2003 | D2 | Jan. 7, 2026, 5:27 p.m. | OK | Java 21 | TESTS | 30 | 906 | 71168000 | ||
| 356850763 | wenbozh | D2 | Jan. 7, 2026, 4:50 p.m. | OK | Java 21 | TESTS | 30 | 921 | 49459200 | ||
| 356907663 | xmjlove | D2 | Jan. 8, 2026, 5:57 a.m. | OK | Java 21 | TESTS | 30 | 921 | 101785600 | ||
| 356851285 | Hastorius | D2 | Jan. 7, 2026, 4:51 p.m. | OK | Java 21 | TESTS | 30 | 1000 | 100147200 | ||
| 356862561 | ryuk_baba | D2 | Jan. 7, 2026, 5:24 p.m. | OK | Java 21 | TESTS | 30 | 1078 | 67276800 | ||
| 356857204 | etian6795 | D2 | Jan. 7, 2026, 5:08 p.m. | OK | Java 21 | TESTS | 30 | 1109 | 60723200 | ||
| 356857205 | tohoshinki254 | D2 | Jan. 7, 2026, 5:08 p.m. | OK | Java 8 | TESTS | 30 | 937 | 74035200 | ||
| 356875755 | ibraheemkureshi | D2 | Jan. 7, 2026, 7:29 p.m. | OK | PyPy 3-64 | TESTS | 30 | 656 | 77619200 | ||
| 356851896 | k1tty- | D2 | Jan. 7, 2026, 4:53 p.m. | OK | PyPy 3-64 | TESTS | 30 | 687 | 75468800 | ||
| 356859827 | flakepym | D2 | Jan. 7, 2026, 5:16 p.m. | OK | PyPy 3-64 | TESTS | 30 | 687 | 88780800 | ||
| 356851826 | sieun0228 | D2 | Jan. 7, 2026, 4:53 p.m. | OK | PyPy 3-64 | TESTS | 30 | 687 | 89804800 | ||
| 356859559 | ericshen19555 | D2 | Jan. 7, 2026, 5:15 p.m. | OK | PyPy 3-64 | TESTS | 30 | 687 | 91443200 | ||
| 356852785 | a_cedia | D2 | Jan. 7, 2026, 4:55 p.m. | OK | PyPy 3-64 | TESTS | 30 | 703 | 94105600 | ||
| 356854991 | HumbleRobo | D2 | Jan. 7, 2026, 5:02 p.m. | OK | PyPy 3-64 | TESTS | 30 | 765 | 99942400 | ||
| 356851932 | MohamedAdel_2025 | D2 | Jan. 7, 2026, 4:53 p.m. | OK | PyPy 3-64 | TESTS | 30 | 765 | 127692800 | ||
| 356874017 | OAY71011 | D2 | Jan. 7, 2026, 7:13 p.m. | OK | PyPy 3-64 | TESTS | 30 | 796 | 121241600 | ||
| 356855196 | gdstw | D2 | Jan. 7, 2026, 5:02 p.m. | OK | PyPy 3-64 | TESTS | 30 | 859 | 82022400 | ||
| 356864553 | Master-Yug | D2 | Jan. 7, 2026, 5:30 p.m. | OK | Python 3 | TESTS | 30 | 1031 | 128000000 | ||
| 356861552 | noir123 | D2 | Jan. 7, 2026, 5:21 p.m. | OK | Python 3 | TESTS | 30 | 1140 | 71577600 | ||
| 356859328 | HariSriramula | D2 | Jan. 7, 2026, 5:14 p.m. | OK | Python 3 | TESTS | 30 | 1171 | 133836800 | ||
| 356852264 | tej1997 | D2 | Jan. 7, 2026, 4:54 p.m. | OK | Python 3 | TESTS | 30 | 1296 | 137318400 | ||
| 356853283 | zilinj | D2 | Jan. 7, 2026, 4:57 p.m. | OK | Ruby 3 | TESTS | 30 | 750 | 96768000 | ||
| 356857689 | despair | D2 | Jan. 7, 2026, 5:09 p.m. | OK | Rust 2024 | TESTS | 30 | 218 | 48947200 | ||
| 356854426 | Ze_nith | D2 | Jan. 7, 2026, 5 p.m. | OK | Rust 2024 | TESTS | 30 | 234 | 45465600 | ||
| 356857431 | darkkcyan | D2 | Jan. 7, 2026, 5:09 p.m. | OK | Rust 2024 | TESTS | 30 | 265 | 55500800 |
Back to search problems