Codeforces Round 1042 (Div. 3)

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
2131 Codeforces Round 1042 (Div. 3) FINISHED False 8100 21569123 Aug. 10, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 14193 ) D Arboris Contractio PROGRAMMING graphs greedy trees

Kagari is preparing to archive a tree, and she knows the cost of doing so will depend on its diameter(^{\text{∗}}). To keep the expense down, her goal is to shrink the diameter as much as possible first. She can perform the following operation on the tree: Choose two vertices (s) and (t). Let the sequence of vertices on the simple path(^{\text{†}}) from (s) to (t) be (v_0, v_1, \dots, v_k), where (v_0 = s) and (v_k = t). Remove all edges along the path. In other words, remove edges ((v_0, v_1), (v_1, v_2), \dots, (v_{k-1}, v_k)). Connect vertices (v_1, v_2, \dots, v_k) directly to (v_0). In other words, add edges ((v_0, v_1), (v_0, v_2), \dots, (v_0, v_k)). It can be shown that the graph is still a tree after the operation. Help her determine the minimum number of operations required to achieve the minimal diameter. (^{\text{∗}})The diameter of a tree is the longest possible distance between any pair of vertices. The distance itself is measured by the number of edges on the unique simple path connecting them. (^{\text{†}})A simple path is a path between two vertices in a tree that does not visit any vertex more than once. It can be shown that the simple path between any two vertices is always unique. 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 one integer (n) ((2 \le n \le 2 \cdot 10^5)) — the number of the vertices in the tree. The following (n-1) lines of each test case describe the tree. Each of the lines contains two integers (u) and (v) ((1 \le u, v \le n), (u \neq v)) that indicate an edge between vertex (u) and (v). It is guaranteed that these edges form a tree. It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, output one intege

Tutorials

Codeforces Round 1042 (Div. 3) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
333450718 og.kostya D Aug. 10, 2025, 5:16 p.m. OK C# 13 TESTS 11 234 24883200
333477356 StarsIntoSea_SY D Aug. 11, 2025, 1:05 a.m. OK C++17 (GCC 7-32) TESTS 11 109 5632000
333477565 look_itz_ishaan D Aug. 11, 2025, 1:09 a.m. OK C++17 (GCC 7-32) TESTS 11 124 2560000
333468252 Ecoch D Aug. 10, 2025, 8:36 p.m. OK C++17 (GCC 7-32) TESTS 11 124 65126400
333449597 Mamun01 D Aug. 10, 2025, 5:09 p.m. OK C++17 (GCC 7-32) TESTS 11 139 0
333489251 Optimus_prime6 D Aug. 11, 2025, 4:04 a.m. OK C++17 (GCC 7-32) TESTS 11 155 102400
333480716 414s_boy D Aug. 11, 2025, 2:03 a.m. OK C++17 (GCC 7-32) TESTS 11 155 4812800
333451628 iL.nayR D Aug. 10, 2025, 5:23 p.m. OK C++17 (GCC 7-32) TESTS 11 155 4812800
333448659 Milton_098 D Aug. 10, 2025, 5:04 p.m. OK C++17 (GCC 7-32) TESTS 11 155 16076800
333499048 mattgryts D Aug. 11, 2025, 6:05 a.m. OK C++17 (GCC 7-32) TESTS 11 156 11980800
333497254 ilovedao D Aug. 11, 2025, 5:47 a.m. OK C++17 (GCC 7-32) TESTS 11 171 921600
333469694 rezidentura D Aug. 10, 2025, 9:05 p.m. OK C++20 (GCC 13-64) TESTS 11 109 0
333493576 SamarthaKhare D Aug. 11, 2025, 5:08 a.m. OK C++20 (GCC 13-64) TESTS 11 124 1228800
333452707 salavat_math D Aug. 10, 2025, 5:31 p.m. OK C++20 (GCC 13-64) TESTS 11 124 2560000
333480831 ___PatrickChen___ D Aug. 11, 2025, 2:05 a.m. OK C++20 (GCC 13-64) TESTS 11 124 4812800
333447211 Lucky_2004 D Aug. 10, 2025, 4:57 p.m. OK C++20 (GCC 13-64) TESTS 11 140 5120000
333477665 Dave233 D Aug. 11, 2025, 1:11 a.m. OK C++20 (GCC 13-64) TESTS 11 171 6860800
333462991 rakim_ D Aug. 10, 2025, 7:15 p.m. OK C++20 (GCC 13-64) TESTS 11 171 6860800
333472607 sayon29 D Aug. 10, 2025, 10:23 p.m. OK C++20 (GCC 13-64) TESTS 11 171 7577600
333462752 sudipjana777 D Aug. 10, 2025, 7:12 p.m. OK C++20 (GCC 13-64) TESTS 11 171 7680000
333465985 souravone D Aug. 10, 2025, 7:58 p.m. OK C++20 (GCC 13-64) TESTS 11 171 9216000
333478449 Hoang_Thien_De D Aug. 11, 2025, 1:27 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 93 102400
333475781 taj D Aug. 11, 2025, 12:24 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 108 1126400
333452867 TMQuitten D Aug. 10, 2025, 5:32 p.m. OK C++23 (GCC 14-64, msys2) TESTS 11 108 15564800
333493964 bestprogrammer_no1 D Aug. 11, 2025, 5:13 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 109 0
333464053 knovozhilov D Aug. 10, 2025, 7:28 p.m. OK C++23 (GCC 14-64, msys2) TESTS 11 109 102400
333470862 zhenyailyina D Aug. 10, 2025, 9:32 p.m. OK C++23 (GCC 14-64, msys2) TESTS 11 140 5427200
333489892 Error31121 D Aug. 11, 2025, 4:15 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 155 0
333458767 codevode D Aug. 10, 2025, 6:25 p.m. OK C++23 (GCC 14-64, msys2) TESTS 11 155 6144000
333450342 shadowkj D Aug. 10, 2025, 5:14 p.m. OK C++23 (GCC 14-64, msys2) TESTS 11 155 11673600
333445050 huanqizhen D Aug. 10, 2025, 4:49 p.m. OK C++23 (GCC 14-64, msys2) TESTS 11 156 7475200
333444835 eldistinto D Aug. 10, 2025, 4:49 p.m. OK GNU C11 TESTS 11 140 9625600
333448552 joseantonio.vegaruiz D Aug. 10, 2025, 5:04 p.m. OK Java 21 TESTS 11 234 716800
333488398 punitpunde D Aug. 11, 2025, 3:52 a.m. OK Java 21 TESTS 11 608 37376000
333490224 punitpunde D Aug. 11, 2025, 4:20 a.m. OK Java 21 TESTS 11 671 38502400
333453892 GaleStarr D Aug. 10, 2025, 5:40 p.m. OK Java 21 TESTS 11 687 30310400
333496794 pratham795 D Aug. 11, 2025, 5:42 a.m. OK Java 21 TESTS 11 703 30105600
333452763 echogenesis D Aug. 10, 2025, 5:31 p.m. OK Java 21 TESTS 11 733 29388800
333471943 KRRISH9977 D Aug. 10, 2025, 10:02 p.m. OK Java 21 TESTS 11 734 36966400
333448897 DreamyDusk D Aug. 10, 2025, 5:05 p.m. OK Java 21 TESTS 11 749 39833600
333486342 shiva___np D Aug. 11, 2025, 3:22 a.m. OK Java 21 TESTS 11 765 36659200
333469696 ishanmandal5 D Aug. 10, 2025, 9:05 p.m. OK Java 21 TESTS 11 765 36864000
333480347 adityadutt D Aug. 11, 2025, 1:58 a.m. OK Java 8 TESTS 11 577 33382400
333468959 saurabh_2701 D Aug. 10, 2025, 8:50 p.m. OK Java 8 TESTS 11 608 34099200
333498079 achyut88 D Aug. 11, 2025, 5:55 a.m. OK Java 8 TESTS 11 686 62976000
333468189 skk_codes D Aug. 10, 2025, 8:35 p.m. OK Java 8 TESTS 11 1124 28057600
333447941 syed_raza D Aug. 10, 2025, 5:01 p.m. OK Java 8 TESTS 11 1327 31641600
333491300 JiyaKap1409 D Aug. 11, 2025, 4:36 a.m. OK Java 8 TESTS 11 1343 28057600
333446694 Aroson D Aug. 10, 2025, 4:55 p.m. OK PyPy 3 TESTS 11 1218 22118400
333445937 nncoder07 D Aug. 10, 2025, 4:52 p.m. OK PyPy 3 TESTS 11 1358 23244800
333479779 Coderhype D Aug. 11, 2025, 1:49 a.m. OK PyPy 3-64 TESTS 11 218 49356800
333464299 bishoprunner D Aug. 10, 2025, 7:32 p.m. OK PyPy 3-64 TESTS 11 343 41369600
333456118 gardengnome D Aug. 10, 2025, 5:59 p.m. OK PyPy 3-64 TESTS 11 375 14131200
333465868 jvatsal0709 D Aug. 10, 2025, 7:56 p.m. OK PyPy 3-64 TESTS 11 390 34611200
333474336 alexwice D Aug. 10, 2025, 11:29 p.m. OK PyPy 3-64 TESTS 11 421 35430400
333484794 fatalerror D Aug. 11, 2025, 3:01 a.m. OK PyPy 3-64 TESTS 11 436 36556800
333444209 maharaja D Aug. 10, 2025, 4:48 p.m. OK PyPy 3-64 TESTS 11 436 47718400
333453146 PeCoP D Aug. 10, 2025, 5:34 p.m. OK PyPy 3-64 TESTS 11 437 41574400
333444820 yavra D Aug. 10, 2025, 4:49 p.m. OK PyPy 3-64 TESTS 11 452 34508800
333495238 yoichii D Aug. 11, 2025, 5:28 a.m. OK PyPy 3-64 TESTS 11 467 58880000
333456753 mpentus D Aug. 10, 2025, 6:06 p.m. OK Python 3 TESTS 11 468 9625600
333448321 xodnd D Aug. 10, 2025, 5:02 p.m. OK Python 3 TESTS 11 546 36454400
333498482 wayneisadog D Aug. 11, 2025, 6 a.m. OK Python 3 TESTS 11 562 40448000
333490757 eugalt D Aug. 11, 2025, 4:28 a.m. OK Python 3 TESTS 11 655 39936000
333444677 soundarzozm D Aug. 10, 2025, 4:49 p.m. OK Python 3 TESTS 11 655 65843200
333490085 eugalt D Aug. 11, 2025, 4:18 a.m. OK Python 3 TESTS 11 671 38400000
333445613 kuldas1531 D Aug. 10, 2025, 4:49 p.m. OK Python 3 TESTS 11 717 45363200
333489792 eugalt D Aug. 11, 2025, 4:13 a.m. OK Python 3 TESTS 11 734 38400000
333443445 adam.elfayoumi06 D Aug. 10, 2025, 4:47 p.m. OK Python 3 TESTS 11 827 53760000
333453012 ___a_s_1_2___ D Aug. 10, 2025, 5:33 p.m. OK Python 3 TESTS 11 921 79667200

remove filters

Back to search problems