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 |
|---|---|---|---|---|---|---|
| 2254 | Codeforces Round 1114 (Div. 3) | FINISHED | False | 8100 | 3684253 | Aug. 4, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 1206 ) | G | Nightcrawler | PROGRAMMING | data structures dfs and similar dp greedy sortings trees |
Yousef has given you a rooted tree(^{\text{∗}}) with (n) vertices, where the root is vertex (1). Each vertex (i) is assigned an integer (a_i). You must partition the set of all (n) vertices into exactly (k) disjoint subsets (S_1, S_2, \dots, S_k) (that is, each vertex must belong to exactly one of the (k) sets) such that the following condition is satisfied: For any subset (S_i) containing two or more vertices, for every pair of vertices (u, v \in S_i), one must be the ancestor(^{\text{†}}) of the other (i.e., they must all lie on the same path extending from the root toward a leaf). The score of a subset (S_i) is defined as the maximum value (a_u) among all vertices (u) in that subset. The score of the partition is the sum of the scores of the (k) subsets. In other words, the score of the partition is equal to (\sum\limits_{i=1}^{k} \max\limits_{u \in S_i} a_u). For every integer (k) from (1) to (n), calculate the maximum possible score of a partition. If it is impossible to partition the tree into exactly (k) subsets that satisfy the condition, output (-1). (^{\text{∗}})A tree is a connected graph without cycles. A rooted tree is a tree where one vertex is special and called the root. (^{\text{†}})An ancestor of vertex (v) is any vertex on the simple path from (v) to the root, including the root, but not including (v). The root has no ancestors. The first line contains an integer (t) ((1 \le t \le 10^4)) — the number of test cases. The first line of each test case contains an integer (n) ((3 \le n \le 2 \cdot 10^5)) — the number of vertices. The second line of each test case contains (n) integers (a_1, a_2, \dots, a_n) ((1 \le a_i \le 10^9)) — the values of the vertices. The third line of each test case contains (n-1) integers (p_2, p_3, \dots, p_n) ((1 \le p_i \lt i)), where (p_i) is the parent of the $$ |
| Tutorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 385674142 | naixinganhuoyyp | G | Aug. 4, 2026, 4:49 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 187 | 3379200 | ||
| 385671439 | Curt | G | Aug. 4, 2026, 4:45 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 203 | 4198400 | ||
| 385673020 | muvum | G | Aug. 4, 2026, 4:47 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 203 | 8089600 | ||
| 385669366 | therealdoug0986 | G | Aug. 4, 2026, 4:41 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 218 | 2764800 | ||
| 385673395 | Listener1379 | G | Aug. 4, 2026, 4:48 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 218 | 4198400 | ||
| 385822868 | loser_02 | G | Aug. 6, 2026, 2:20 a.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 218 | 20377600 | ||
| 385711499 | wangmingwei | G | Aug. 5, 2026, 3:43 a.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 234 | 14336000 | ||
| 385834720 | abhinavgautam9 | G | Aug. 6, 2026, 5:02 a.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 234 | 19456000 | ||
| 385810581 | P0LyFish | G | Aug. 5, 2026, 9:29 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 234 | 20070400 | ||
| 385672794 | rw0157 | G | Aug. 4, 2026, 4:47 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 234 | 20480000 | ||
| 385698898 | classic | G | Aug. 4, 2026, 11:49 p.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 125 | 3379200 | ||
| 385828783 | Joacoini | G | Aug. 6, 2026, 3:26 a.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 140 | 7372800 | ||
| 385712507 | lmf_up | G | Aug. 5, 2026, 3:59 a.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 156 | 11776000 | ||
| 385808802 | olasiliksizci | G | Aug. 5, 2026, 8:49 p.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 156 | 25804800 | ||
| 385720770 | Just_Love_You | G | Aug. 5, 2026, 5:55 a.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 156 | 25804800 | ||
| 385818593 | GoodThings | G | Aug. 6, 2026, 1:28 a.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 171 | 14131200 | ||
| 385670794 | dminhtle | G | Aug. 4, 2026, 4:44 p.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 171 | 26726400 | ||
| 385820240 | GoodThings | G | Aug. 6, 2026, 1:51 a.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 187 | 14028800 | ||
| 385836851 | broxxoli | G | Aug. 6, 2026, 5:35 a.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 187 | 24268800 | ||
| 385815650 | Acce1erator07 | G | Aug. 6, 2026, 12:16 a.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 187 | 25804800 | ||
| 385671761 | a.garbart | G | Aug. 4, 2026, 4:45 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 140 | 3993600 | ||
| 385670056 | yamsy | G | Aug. 4, 2026, 4:42 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 140 | 14438400 | ||
| 385824126 | woden_yzh | G | Aug. 6, 2026, 2:33 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 156 | 16179200 | ||
| 385795176 | Moth_0642 | G | Aug. 5, 2026, 6:11 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 156 | 25088000 | ||
| 385713026 | wanbitter | G | Aug. 5, 2026, 4:08 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 156 | 25088000 | ||
| 385669917 | sav | G | Aug. 4, 2026, 4:42 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 171 | 5836800 | ||
| 385815848 | wuyi2007 | G | Aug. 6, 2026, 12:23 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 171 | 9318400 | ||
| 385715391 | lrnnz | G | Aug. 5, 2026, 4:44 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 171 | 9523200 | ||
| 385673178 | _rudra_pratap_singh_ | G | Aug. 4, 2026, 4:48 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 171 | 23552000 | ||
| 385812000 | xoceankingx | G | Aug. 5, 2026, 10:08 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 171 | 24166400 | ||
| 385672068 | RoadToGlory | G | Aug. 4, 2026, 4:46 p.m. | OK | Java 21 | TESTS | 22 | 281 | 1945600 | ||
| 385711442 | vineetiwari | G | Aug. 5, 2026, 3:43 a.m. | OK | Java 21 | TESTS | 22 | 1234 | 147456000 | ||
| 385802003 | knightL | G | Aug. 5, 2026, 7:08 p.m. | OK | Java 21 | TESTS | 22 | 1609 | 98611200 | ||
| 385798143 | ironman263 | G | Aug. 5, 2026, 6:31 p.m. | OK | Java 21 | TESTS | 22 | 1718 | 104243200 | ||
| 385704112 | ramumali2002 | G | Aug. 5, 2026, 1:40 a.m. | OK | PyPy 3 | TESTS | 22 | 1000 | 30822400 | ||
| 385694520 | Arvind215271 | G | Aug. 4, 2026, 10:07 p.m. | OK | PyPy 3 | TESTS | 22 | 1953 | 111104000 | ||
| 385670156 | Jack2Codes4 | G | Aug. 4, 2026, 4:43 p.m. | OK | PyPy 3-64 | TESTS | 22 | 578 | 69632000 | ||
| 385701971 | Little_Sheep_Yawn | G | Aug. 5, 2026, 1:01 a.m. | OK | PyPy 3-64 | TESTS | 22 | 609 | 46182400 | ||
| 385838721 | chmpro | G | Aug. 6, 2026, 6:02 a.m. | OK | PyPy 3-64 | TESTS | 22 | 750 | 50585600 | ||
| 385717109 | hxu10 | G | Aug. 5, 2026, 5:08 a.m. | OK | PyPy 3-64 | TESTS | 22 | 1078 | 73113600 | ||
| 385706728 | BitForge | G | Aug. 5, 2026, 2:25 a.m. | OK | Python 3 | TESTS | 22 | 578 | 88166400 | ||
| 385719808 | adityaa6 | G | Aug. 5, 2026, 5:43 a.m. | OK | Python 3 | TESTS | 22 | 640 | 111923200 | ||
| 385714648 | adityaa6 | G | Aug. 5, 2026, 4:32 a.m. | OK | Python 3 | TESTS | 22 | 640 | 111923200 | ||
| 385836350 | kroyl | G | Aug. 6, 2026, 5:27 a.m. | OK | Rust 2024 | TESTS | 22 | 93 | 13414400 |
Back to search problems