Codeforces Round 1023 (Div. 2)

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
2107 Codeforces Round 1023 (Div. 2) FINISHED False 8100 29949923 May 5, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 3520 ) D Apple Tree Traversing PROGRAMMING brute force dfs and similar greedy implementation trees

There is an apple tree with (n) nodes, initially with one apple at each node. You have a paper with you, initially with nothing written on it. You are traversing on the apple tree, by doing the following action as long as there is at least one apple left: Choose an apple path ((u,v)). A path ((u,v)) is called an apple path if and only if for every node on the path ((u,v)), there's an apple on it. Let (d) be the number of apples on the path, write down three numbers ((d,u,v)), in this order, on the paper. Then remove all the apples on the path ((u,v)). Here, the path ((u, v)) refers to the sequence of vertices on the unique shortest walk from (u) to (v). Let the number sequence on the paper be (a). Your task is to find the lexicographically largest possible sequence (a). 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 number (n) ((1 \le n \le 1.5 \cdot 10^5)). The following (n-1) lines of each test case contain two numbers (u,v) ((1 \le u,v \le n)). It's guaranteed that the input forms a tree. It is guaranteed that the sum of (n) over all test cases does not exceed (1.5 \cdot 10^5). For each test case, output the lexicographically largest sequence possible (a_1, a_2, \ldots, a_{|a|}). It can be shown that (|a| \le 3 \cdot n). In the first test case, we do the following steps: Choose the apple path ((4, 3)). This path consists of the nodes (4, 1, 3), and each of them have an apple (so it is a valid apple path). (d = 3) as there are (3) apples on this path. Append (3, 4, 3) in that order to our sequence (a). Now, remove the apples from these (3) vertices. Only node (2) has an apple left. Choose the apple path ((2, 2)). This path only consists of the single node (2). (d = 1)

Tutorials

Codeforces Round 1023 (Div 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
318560370 mban259 D May 5, 2025, 11:34 p.m. OK C# 10 TESTS 28 1936 55910400
318544084 MrB0NAN D May 5, 2025, 6:30 p.m. OK C# 10 TESTS 28 4953 99942400
318549678 SpinSpen D May 5, 2025, 7:35 p.m. OK C++17 (GCC 7-32) TESTS 28 296 13824000
318549388 Con_Lieu_Can_Fauz D May 5, 2025, 7:30 p.m. OK C++17 (GCC 7-32) TESTS 28 343 25088000
318524608 Hanyu_23 D May 5, 2025, 4:39 p.m. OK C++17 (GCC 7-32) TESTS 28 375 7065600
318523942 Sami_Massah D May 5, 2025, 4:37 p.m. OK C++17 (GCC 7-32) TESTS 28 468 52633600
318572069 dsn_20051209 D May 6, 2025, 2:35 a.m. OK C++17 (GCC 7-32) TESTS 28 515 9625600
318582060 ascia D May 6, 2025, 5:27 a.m. OK C++17 (GCC 7-32) TESTS 28 546 11468800
318524275 kissgergely D May 5, 2025, 4:38 p.m. OK C++17 (GCC 7-32) TESTS 28 546 47718400
318572904 SJCHSKY D May 6, 2025, 2:50 a.m. OK C++17 (GCC 7-32) TESTS 28 561 22118400
318552265 ChineseBheL D May 5, 2025, 8:15 p.m. OK C++17 (GCC 7-32) TESTS 28 593 13209600
318572786 cube_escape D May 6, 2025, 2:48 a.m. OK C++17 (GCC 7-32) TESTS 28 593 22118400
318574540 beta99999 D May 6, 2025, 3:22 a.m. OK C++20 (GCC 13-64) TESTS 28 93 6963200
318542205 Stepaijio D May 5, 2025, 6:12 p.m. OK C++20 (GCC 13-64) TESTS 28 296 29286400
318569353 ma_niu_bi D May 6, 2025, 1:32 a.m. OK C++20 (GCC 13-64) TESTS 28 296 34816000
318524274 PMiguelez D May 5, 2025, 4:38 p.m. OK C++20 (GCC 13-64) TESTS 28 296 44441600
318574075 Qian_Feng D May 6, 2025, 3:13 a.m. OK C++20 (GCC 13-64) TESTS 28 311 52326400
318557852 AnAverageElectrician D May 5, 2025, 10:05 p.m. OK C++20 (GCC 13-64) TESTS 28 328 67584000
318570870 ma_niu_bi D May 6, 2025, 2:07 a.m. OK C++20 (GCC 13-64) TESTS 28 343 54886400
318541426 saboten D May 5, 2025, 6:04 p.m. OK C++20 (GCC 13-64) TESTS 28 358 53043200
318570840 ma_niu_bi D May 6, 2025, 2:06 a.m. OK C++20 (GCC 13-64) TESTS 28 359 54988800
318549266 c8216 D May 5, 2025, 7:29 p.m. OK C++20 (GCC 13-64) TESTS 28 405 21401600
318569741 xjt01 D May 6, 2025, 1:42 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 234 60313600
318569316 xjt01 D May 6, 2025, 1:31 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 281 68096000
318568985 xjt01 D May 6, 2025, 1:23 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 296 68096000
318571311 TodayIsSunday D May 6, 2025, 2:18 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 312 77107200
318558032 AlexRex0 D May 5, 2025, 10:11 p.m. OK C++23 (GCC 14-64, msys2) TESTS 28 327 50688000
318557950 AlexRex0 D May 5, 2025, 10:08 p.m. OK C++23 (GCC 14-64, msys2) TESTS 28 327 50688000
318580303 ismoilmirzouz D May 6, 2025, 5:04 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 327 57036800
318525022 Kanaifu D May 5, 2025, 4:40 p.m. OK C++23 (GCC 14-64, msys2) TESTS 28 406 19763200
318569044 bnsczr D May 6, 2025, 1:25 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 436 122675200
318525038 carboxylBase D May 5, 2025, 4:40 p.m. OK C++23 (GCC 14-64, msys2) TESTS 28 452 243200000
318527111 pengin_2000 D May 5, 2025, 4:46 p.m. OK GNU C11 TESTS 28 1499 21708800
318548521 shashanksp851 D May 5, 2025, 7:19 p.m. OK PyPy 3-64 TESTS 28 2234 103219200
318539707 golomb D May 5, 2025, 5:50 p.m. OK PyPy 3-64 TESTS 28 2234 103219200
318555261 the_seal D May 5, 2025, 9:07 p.m. OK PyPy 3-64 TESTS 28 3327 59494400
318537436 krism D May 5, 2025, 5:34 p.m. OK PyPy 3-64 TESTS 28 4921 61849600
318574590 CoCo_Japan_pan D May 6, 2025, 3:23 a.m. OK Rust 2021 TESTS 28 1311 45875200

remove filters

Back to search problems