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 |
|---|---|---|---|---|---|---|
| 2192 | Codeforces Round 1081 (Div. 2) | FINISHED | False | 7200 | 4721123 | Feb. 21, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 3454 ) | D | Cost of Tree | PROGRAMMING | data structures dfs and similar dp trees |
For a tree (T) with root (r), where each node (u) has a value (a_u) associated with it, the cost of the tree defined as: ()\sum_{u\in T} (a_u \cdot d(r,u))() Here, this sum is taken over all nodes (u) in the tree (T), and (d(r,u)) denotes the number of edges on the shortest path from node (r) to node (u) on a tree. You are given a tree consisting of (n) nodes, rooted at node (1). Each node (i) has a value (a_i) assigned to it. For each (r) from (1) to (n), please solve the following problem independently: Consider the subtree of node (r) with respect to node (1). Formally, the subtree of node (r) is the tree consisting of all nodes (u) such that the shortest path from (1) to (u) contains (r). Find the maximum cost of the subtree after performing at most one operation of the following type on the subtree: Choose any node (u) ((u \neq r)). Remove the edge from (u) to the parent of node (u)(^{\text{∗}}). Then, add an edge from (u) to any node (v) that is still reachable from (r). It can be shown that after this operation, the graph remains a tree. (^{\text{∗}})Formally, remove the edge from (u) to (p), where (p) is the unique node satisfying (d(u,p)=1) and (d(u,r)=d(p,r)+1) 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 testcase contains a single integer (n) ((1 \le n \le 2 \cdot 10^5)) — the count of nodes in the tree. The second line of each testcase contains (n) integers (a_1, a_2, \ldots, a_n) ((1 \le a_i \le 2 \cdot 10^5)). Then (n − 1) lines follow, the (i)-th line containing two integers (u) and (v) ((1 \le u, v \le n)) — the two nodes that the (i)-th edge connects. It is guaranteed that the given edges form a tree. |
| Codeforces Round 1081 (Div. 2) Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 363900709 | anonymous46 | D | Feb. 21, 2026, 4:27 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 265 | 18739200 | ||
| 363902091 | thecff | D | Feb. 21, 2026, 4:31 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 281 | 18227200 | ||
| 363907005 | Sunyn | D | Feb. 21, 2026, 5:20 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 281 | 23449600 | ||
| 363897549 | ESTZ | D | Feb. 21, 2026, 4:20 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 296 | 33894400 | ||
| 363907996 | IM_VERY_STUPID | D | Feb. 21, 2026, 5:28 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 312 | 27545600 | ||
| 363907485 | weixiaog222 | D | Feb. 21, 2026, 5:23 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 312 | 95436800 | ||
| 363950992 | S106 | D | Feb. 22, 2026, 4:24 a.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 343 | 26419200 | ||
| 363913878 | JonathanDS | D | Feb. 21, 2026, 6:11 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 343 | 42291200 | ||
| 363935958 | linyuqin | D | Feb. 21, 2026, 10:19 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 343 | 43417600 | ||
| 363940518 | legoflowers | D | Feb. 22, 2026, 12:10 a.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 359 | 38400000 | ||
| 363896049 | wsr999 | D | Feb. 21, 2026, 4:16 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 218 | 36147200 | ||
| 363906789 | Ruliea_ | D | Feb. 21, 2026, 5:19 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 218 | 67993600 | ||
| 363953835 | wuyifan0918 | D | Feb. 22, 2026, 5:15 a.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 234 | 31334400 | ||
| 363900458 | chemih | D | Feb. 21, 2026, 4:27 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 34611200 | ||
| 363895670 | Danhuang_uon | D | Feb. 21, 2026, 4:15 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 250 | 59392000 | ||
| 363950010 | bourbon111 | D | Feb. 22, 2026, 4:07 a.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 265 | 37273600 | ||
| 363898626 | 2021sunzishan | D | Feb. 21, 2026, 4:22 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 265 | 38502400 | ||
| 363912819 | biank | D | Feb. 21, 2026, 6:02 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 281 | 35020800 | ||
| 363898645 | DaShouZi | D | Feb. 21, 2026, 4:22 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 281 | 40140800 | ||
| 363908486 | Redial | D | Feb. 21, 2026, 5:31 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 281 | 42803200 | ||
| 363922043 | Kaedemaple | D | Feb. 21, 2026, 7:23 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 234 | 62054400 | ||
| 363895999 | wudidaniuma | D | Feb. 21, 2026, 4:16 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 35020800 | ||
| 363935378 | Zhanadil | D | Feb. 21, 2026, 10:08 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 37888000 | ||
| 363912222 | xiaogan882 | D | Feb. 21, 2026, 5:58 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 250 | 55808000 | ||
| 363956702 | khushicodes03 | D | Feb. 22, 2026, 5:56 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 265 | 34713600 | ||
| 363950824 | yyy..wait | D | Feb. 22, 2026, 4:21 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 265 | 34713600 | ||
| 363950445 | gooonn | D | Feb. 22, 2026, 4:14 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 265 | 34713600 | ||
| 363923142 | szx233 | D | Feb. 21, 2026, 7:34 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 265 | 35123200 | ||
| 363947162 | P2441M | D | Feb. 22, 2026, 3:06 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 265 | 36352000 | ||
| 363954832 | IKUN_111 | D | Feb. 22, 2026, 5:30 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 265 | 37376000 | ||
| 363901403 | knightL | D | Feb. 21, 2026, 4:29 p.m. | OK | Java 21 | TESTS | 30 | 406 | 39219200 | ||
| 363904018 | kartik__sethi | D | Feb. 21, 2026, 4:34 p.m. | OK | Java 21 | TESTS | 30 | 921 | 106496000 | ||
| 363907394 | Yoda1122 | D | Feb. 21, 2026, 5:22 p.m. | OK | Java 21 | TESTS | 30 | 937 | 82841600 | ||
| 363916843 | testtest111ksjfrdvn | D | Feb. 21, 2026, 6:34 p.m. | OK | Java 21 | TESTS | 30 | 1000 | 87040000 | ||
| 363906857 | Yoda1122 | D | Feb. 21, 2026, 5:20 p.m. | OK | Java 21 | TESTS | 30 | 1015 | 83046400 | ||
| 363933961 | shubhansh_gupta | D | Feb. 21, 2026, 9:42 p.m. | OK | Java 21 | TESTS | 30 | 1031 | 86220800 | ||
| 363933853 | rachit.gupta | D | Feb. 21, 2026, 9:40 p.m. | OK | Java 21 | TESTS | 30 | 1031 | 86220800 | ||
| 363906764 | xmjlove | D | Feb. 21, 2026, 5:19 p.m. | OK | Java 21 | TESTS | 30 | 1109 | 117657600 | ||
| 363918868 | GaleStarr | D | Feb. 21, 2026, 6:53 p.m. | OK | Java 21 | TESTS | 30 | 1109 | 146841600 | ||
| 363900943 | Mathecoach | D | Feb. 21, 2026, 4:28 p.m. | OK | Java 21 | TESTS | 30 | 1125 | 209817600 | ||
| 363908783 | kamranm | D | Feb. 21, 2026, 5:33 p.m. | OK | Java 8 | TESTS | 30 | 843 | 249344000 | ||
| 363919704 | kevin_0911 | D | Feb. 21, 2026, 7:02 p.m. | OK | Java 8 | TESTS | 30 | 968 | 68505600 | ||
| 363896637 | letscod2021 | D | Feb. 21, 2026, 4:17 p.m. | OK | Java 8 | TESTS | 30 | 984 | 161075200 | ||
| 363920981 | kevin_0911 | D | Feb. 21, 2026, 7:14 p.m. | OK | Java 8 | TESTS | 30 | 1000 | 64000000 | ||
| 363921226 | kevin_0911 | D | Feb. 21, 2026, 7:16 p.m. | OK | Java 8 | TESTS | 30 | 1031 | 64000000 | ||
| 363911245 | godAngryOver | D | Feb. 21, 2026, 5:51 p.m. | OK | Java 8 | TESTS | 30 | 1468 | 118169600 | ||
| 363894610 | aiyucodes | D | Feb. 21, 2026, 4:12 p.m. | OK | Kotlin 2.2 | TESTS | 30 | 1250 | 201420800 | ||
| 363938035 | isa773 | D | Feb. 21, 2026, 11:06 p.m. | OK | PyPy 3-64 | TESTS | 30 | 703 | 118886400 | ||
| 363936905 | Only365 | D | Feb. 21, 2026, 10:39 p.m. | OK | PyPy 3-64 | TESTS | 30 | 718 | 62156800 | ||
| 363901958 | vxgmichel | D | Feb. 21, 2026, 4:30 p.m. | OK | PyPy 3-64 | TESTS | 30 | 765 | 61235200 | ||
| 363896465 | longjourney | D | Feb. 21, 2026, 4:17 p.m. | OK | PyPy 3-64 | TESTS | 30 | 921 | 59801600 | ||
| 363909658 | jgs03177 | D | Feb. 21, 2026, 5:40 p.m. | OK | PyPy 3-64 | TESTS | 30 | 984 | 81100800 | ||
| 363952667 | Mentholzzz | D | Feb. 22, 2026, 4:54 a.m. | OK | PyPy 3-64 | TESTS | 30 | 1015 | 106188800 | ||
| 363952665 | akane646 | D | Feb. 22, 2026, 4:54 a.m. | OK | PyPy 3-64 | TESTS | 30 | 1046 | 76390400 | ||
| 363910526 | akane646 | D | Feb. 21, 2026, 5:46 p.m. | OK | PyPy 3-64 | TESTS | 30 | 1078 | 78950400 | ||
| 363938164 | bengold10 | D | Feb. 21, 2026, 11:09 p.m. | OK | PyPy 3-64 | TESTS | 30 | 1156 | 78438400 | ||
| 363895906 | Stephen-SS | D | Feb. 21, 2026, 4:16 p.m. | OK | PyPy 3-64 | TESTS | 30 | 1218 | 87756800 | ||
| 363901636 | mingi1178 | D | Feb. 21, 2026, 4:30 p.m. | OK | Python 3 | TESTS | 30 | 1343 | 102297600 | ||
| 363908064 | ai4youej | D | Feb. 21, 2026, 5:28 p.m. | OK | Python 3 | TESTS | 30 | 1421 | 144896000 | ||
| 363954860 | miya145592 | D | Feb. 22, 2026, 5:30 a.m. | OK | Python 3 | TESTS | 30 | 1859 | 134860800 | ||
| 363897104 | GoldbangE | D | Feb. 21, 2026, 4:19 p.m. | OK | Python 3 | TESTS | 30 | 2031 | 139878400 | ||
| 363906965 | shikase | D | Feb. 21, 2026, 5:20 p.m. | OK | Python 3 | TESTS | 30 | 2218 | 146636800 | ||
| 363920050 | pohzipohzi | D | Feb. 21, 2026, 7:05 p.m. | OK | Rust 2024 | TESTS | 30 | 250 | 64102400 | ||
| 363956403 | pohzipohzi | D | Feb. 22, 2026, 5:52 a.m. | OK | Rust 2024 | TESTS | 30 | 250 | 73113600 | ||
| 363900351 | darkkcyan | D | Feb. 21, 2026, 4:27 p.m. | OK | Rust 2024 | TESTS | 30 | 468 | 97996800 |
Back to search problems