Codeforces Round 1051 (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
2143 Codeforces Round 1051 (Div. 2) FINISHED False 7200 18285923 Sept. 17, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 14005 ) C Max Tree PROGRAMMING dfs and similar graphs greedy

You are given a tree consisting of (n) vertices, numbered from (1) to (n). Each of the (n - 1) edges is associated with two non-negative integers (x) and (y). Consider a permutation(^{\text{∗}}) (p) of the integers (1) through (n), where (p_i) represents the value assigned to vertex (i). For an edge ((u, v)), such that (u < v) with associated values (x) and (y), its contribution is defined as follows: () \begin{cases} x & \text{if } p_u > p_v, \\ y & \text{otherwise.} \end{cases} () The value of the permutation is the sum of the contributions from all edges. Your task is to find any permutation (p) that maximizes this total value. (^{\text{∗}})A permutation of length (n) is an array consisting of (n) distinct integers from (1) to (n) in arbitrary order. For example, (2,3,1,5,4) is a permutation, but (1,2,2) is not a permutation ((2) appears twice in the array), and (1,3,4) is also not a permutation ((n=3) but there is (4) in the array). 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 contains a single integer (n) ((2 \le n \le 2 \cdot 10^5)) — the number of vertices in the tree. Each of the next (n - 1) lines contains four integers (u), (v), (x), and (y) ((1 \le u < v \le n), (1 \le x, y \le 10^9)) — describing an edge between vertices (u) and (v) with associated values (x) and (y). It is guarranteed that the given 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, you must output a permutation (p) of the integers (1) through (n) that maximizes the total value as defined in the problem. If there are multiple answers, you can print any of them. In the first

Tutorials

Codeforces Round 1051 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
339143550 nikagam C Sept. 17, 2025, 4:01 p.m. OK C# 10 TESTS 12 639 59801600
339167488 m1_k3 C Sept. 17, 2025, 6:11 p.m. OK C# 13 TESTS 12 296 34099200
339206792 Dzcgjhu C Sept. 18, 2025, 5:31 a.m. OK C++17 (GCC 7-32) TESTS 12 234 2457600
339189412 GhostMFC C Sept. 18, 2025, 12:44 a.m. OK C++17 (GCC 7-32) TESTS 12 234 5632000
339207290 pokysayou C Sept. 18, 2025, 5:38 a.m. OK C++17 (GCC 7-32) TESTS 12 249 0
339190018 3c_273 C Sept. 18, 2025, 12:58 a.m. OK C++17 (GCC 7-32) TESTS 12 249 4096000
339177855 Kirill_Katz_ C Sept. 17, 2025, 8:08 p.m. OK C++17 (GCC 7-32) TESTS 12 250 6553600
339196422 Mr_fan C Sept. 18, 2025, 2:51 a.m. OK C++17 (GCC 7-32) TESTS 12 264 3276800
339145380 revanthsnr C Sept. 17, 2025, 4:06 p.m. OK C++17 (GCC 7-32) TESTS 12 264 3584000
339191899 0.0 C Sept. 18, 2025, 1:41 a.m. OK C++17 (GCC 7-32) TESTS 12 264 4096000
339190117 H_4 C Sept. 18, 2025, 1:01 a.m. OK C++17 (GCC 7-32) TESTS 12 264 10547200
339202405 tmhieu C Sept. 18, 2025, 4:23 a.m. OK C++17 (GCC 7-32) TESTS 12 265 3379200
339154404 GuptaDivyansh26 C Sept. 17, 2025, 4:30 p.m. OK C++20 (GCC 13-64) TESTS 12 202 0
339206052 Grandmaster10 C Sept. 18, 2025, 5:22 a.m. OK C++20 (GCC 13-64) TESTS 12 218 0
339151762 HaDeer.MS C Sept. 17, 2025, 4:24 p.m. OK C++20 (GCC 13-64) TESTS 12 218 8396800
339144577 ASDFGHJKLMNBVCXZQWERT C Sept. 17, 2025, 4:04 p.m. OK C++20 (GCC 13-64) TESTS 12 218 11571200
339202216 _UnstoppableCoder_ C Sept. 18, 2025, 4:19 a.m. OK C++20 (GCC 13-64) TESTS 12 218 16384000
339150781 codeforfriend001 C Sept. 17, 2025, 4:21 p.m. OK C++20 (GCC 13-64) TESTS 12 233 102400
339207908 frexe C Sept. 18, 2025, 5:45 a.m. OK C++20 (GCC 13-64) TESTS 12 233 5734400
339186120 ddadddyyykanshhh C Sept. 17, 2025, 11:19 p.m. OK C++20 (GCC 13-64) TESTS 12 233 5836800
339189867 Mantlemoose C Sept. 18, 2025, 12:55 a.m. OK C++20 (GCC 13-64) TESTS 12 233 5939200
339191077 _sexyboy C Sept. 18, 2025, 1:24 a.m. OK C++20 (GCC 13-64) TESTS 12 233 6451200
339208175 IKUN_111 C Sept. 18, 2025, 5:48 a.m. OK C++23 (GCC 14-64, msys2) TESTS 12 202 0
339207864 IKUN_111 C Sept. 18, 2025, 5:45 a.m. OK C++23 (GCC 14-64, msys2) TESTS 12 202 0
339172379 cmrh.jim C Sept. 17, 2025, 6:56 p.m. OK C++23 (GCC 14-64, msys2) TESTS 12 202 0
339153949 abdulrhman.dev C Sept. 17, 2025, 4:29 p.m. OK C++23 (GCC 14-64, msys2) TESTS 12 202 102400
339207030 egoistlakshya C Sept. 18, 2025, 5:34 a.m. OK C++23 (GCC 14-64, msys2) TESTS 12 202 10342400
339173416 white_two C Sept. 17, 2025, 7:08 p.m. OK C++23 (GCC 14-64, msys2) TESTS 12 202 14745600
339202802 IKUN_111 C Sept. 18, 2025, 4:30 a.m. OK C++23 (GCC 14-64, msys2) TESTS 12 203 0
339193052 Liyxi C Sept. 18, 2025, 1:58 a.m. OK C++23 (GCC 14-64, msys2) TESTS 12 203 16076800
339208986 IKUN_111 C Sept. 18, 2025, 5:57 a.m. OK C++23 (GCC 14-64, msys2) TESTS 12 218 0
339165205 Randiray C Sept. 17, 2025, 5:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 12 218 0
339153914 Mahir_Uddin C Sept. 17, 2025, 4:29 p.m. OK GNU C11 TESTS 12 983 6451200
339147199 Bahmud C Sept. 17, 2025, 4:11 p.m. OK GNU C11 TESTS 12 1062 8396800
339166873 EZIOTHEN00B C Sept. 17, 2025, 6:06 p.m. OK Java 21 TESTS 12 406 21196800
339200667 Freankin C Sept. 18, 2025, 3:50 a.m. OK Java 21 TESTS 12 468 21401600
339154844 adarshsinghzaq12 C Sept. 17, 2025, 4:31 p.m. OK Java 21 TESTS 12 468 21504000
339147027 Nodirjon11 C Sept. 17, 2025, 4:10 p.m. OK Java 21 TESTS 12 483 37068800
339143033 tsunamie C Sept. 17, 2025, 4 p.m. OK Java 21 TESTS 12 483 37068800
339154873 Yash_datoniya C Sept. 17, 2025, 4:32 p.m. OK Java 21 TESTS 12 499 20787200
339149327 VIVEK_SUNKARA_2.0 C Sept. 17, 2025, 4:17 p.m. OK Java 21 TESTS 12 546 1433600
339148360 RahulAhuja2901 C Sept. 17, 2025, 4:14 p.m. OK Java 21 TESTS 12 561 34508800
339182539 mlinear C Sept. 17, 2025, 9:34 p.m. OK Java 21 TESTS 12 671 18227200
339150011 taha.tariq.1999 C Sept. 17, 2025, 4:19 p.m. OK Java 21 TESTS 12 671 33484800
339148745 divyansh515 C Sept. 17, 2025, 4:15 p.m. OK Java 8 TESTS 12 389 21606400
339153336 bhawnapannu27 C Sept. 17, 2025, 4:28 p.m. OK Java 8 TESTS 12 421 21606400
339151270 Shivam_Singh_7457 C Sept. 17, 2025, 4:22 p.m. OK Java 8 TESTS 12 687 14540800
339142713 xmjlove C Sept. 17, 2025, 3:59 p.m. OK Java 8 TESTS 12 718 32563200
339168197 yashvardhan3 C Sept. 17, 2025, 6:17 p.m. OK Java 8 TESTS 12 749 30924800
339146300 jishan5544 C Sept. 17, 2025, 4:08 p.m. OK Java 8 TESTS 12 749 33382400
339143466 Artistic_code C Sept. 17, 2025, 4:01 p.m. OK Java 8 TESTS 12 796 34304000
339170743 Ashu2030 C Sept. 17, 2025, 6:40 p.m. OK Java 8 TESTS 12 811 62156800
339167508 samitsonkar C Sept. 17, 2025, 6:11 p.m. OK Java 8 TESTS 12 921 31232000
339203716 jhemanth C Sept. 18, 2025, 4:47 a.m. OK Java 8 TESTS 12 1015 32972800
339198497 swseverance C Sept. 18, 2025, 3:17 a.m. OK Node.js TESTS 12 1046 129024000
339150299 _Zuno_ C Sept. 17, 2025, 4:19 p.m. OK Node.js TESTS 12 1311 144179200
339151187 Cyros C Sept. 17, 2025, 4:22 p.m. OK PyPy 2 TESTS 12 765 33894400
339163582 siddheart2209 C Sept. 17, 2025, 5:43 p.m. OK PyPy 3 TESTS 12 1171 34508800
339209869 _PD_ C Sept. 18, 2025, 6:06 a.m. OK PyPy 3 TESTS 12 1202 35328000
339142812 Dangerous_Coder_69 C Sept. 17, 2025, 3:59 p.m. OK PyPy 3 TESTS 12 1311 45158400
339145083 sibani C Sept. 17, 2025, 4:05 p.m. OK PyPy 3 TESTS 12 1780 58675200
339147242 bigmahe C Sept. 17, 2025, 4:11 p.m. OK PyPy 3 TESTS 12 1890 33587200
339149863 alphawasd C Sept. 17, 2025, 4:18 p.m. OK PyPy 3 TESTS 12 1936 35328000
339145719 challavishweshwar C Sept. 17, 2025, 4:07 p.m. OK PyPy 3 TESTS 12 1953 60416000
339179493 explainer C Sept. 17, 2025, 8:33 p.m. OK PyPy 3-64 TESTS 12 436 40448000
339183471 mathsplanck C Sept. 17, 2025, 9:58 p.m. OK PyPy 3-64 TESTS 12 437 41779200
339146906 Uday_parmar21 C Sept. 17, 2025, 4:10 p.m. OK PyPy 3-64 TESTS 12 452 40140800
339176506 ketuOP C Sept. 17, 2025, 7:48 p.m. OK PyPy 3-64 TESTS 12 468 32153600
339202511 gardengnome C Sept. 18, 2025, 4:25 a.m. OK PyPy 3-64 TESTS 12 483 42086400
339142452 ramya_2129 C Sept. 17, 2025, 3:58 p.m. OK PyPy 3-64 TESTS 12 483 42496000
339150970 fa7271 C Sept. 17, 2025, 4:21 p.m. OK PyPy 3-64 TESTS 12 483 54374400
339144710 udayan8 C Sept. 17, 2025, 4:04 p.m. OK PyPy 3-64 TESTS 12 483 62668800
339149626 wai_wai C Sept. 17, 2025, 4:18 p.m. OK PyPy 3-64 TESTS 12 499 37478400
339142494 23ucs557 C Sept. 17, 2025, 3:58 p.m. OK PyPy 3-64 TESTS 12 499 42393600
339198972 need_thing C Sept. 18, 2025, 3:24 a.m. OK Python 3 TESTS 12 546 55193600
339145301 hanyzead C Sept. 17, 2025, 4:06 p.m. OK Python 3 TESTS 12 577 55193600
339144876 its_farhad C Sept. 17, 2025, 4:04 p.m. OK Python 3 TESTS 12 639 67686400
339155322 kucoders C Sept. 17, 2025, 4:33 p.m. OK Python 3 TESTS 12 640 56217600
339144236 Ramsi C Sept. 17, 2025, 4:03 p.m. OK Python 3 TESTS 12 655 56524800
339202991 SSNSS C Sept. 18, 2025, 4:33 a.m. OK Python 3 TESTS 12 671 106086400
339150713 vaibhav_fusion C Sept. 17, 2025, 4:21 p.m. OK Python 3 TESTS 12 687 46284800
339154835 obrazcoff C Sept. 17, 2025, 4:31 p.m. OK Python 3 TESTS 12 687 102092800
339147156 shseam C Sept. 17, 2025, 4:11 p.m. OK Python 3 TESTS 12 687 106291200
339142924 chiragsharmaa C Sept. 17, 2025, 3:59 p.m. OK Python 3 TESTS 12 702 107212800
339154752 rejoansardar876 C Sept. 17, 2025, 4:31 p.m. OK Rust 2021 TESTS 12 171 35020800
339153024 AnuragYADAV_10 C Sept. 17, 2025, 4:27 p.m. OK Rust 2024 TESTS 12 171 20480000

remove filters

Back to search problems