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 |
|---|---|---|---|---|---|---|
| 2217 | Codeforces Round 1091 (Div. 2) and CodeCraft 26 | FINISHED | False | 8100 | 3165930 | April 7, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 216 ) | H | Closer | PROGRAMMING | dp |
At your networking event, there are (n) deals waiting to happen. Each deal needs exactly two people, and every person is waiting for exactly one deal. So there are (2n) people in total, and each deal ID (1 \ldots n) appears on exactly two people's badges. For corporate reasons, the organisers place each person on a unique vertex in a tree with (2n) vertices. Vertex (v) hosts a person with badge (a_v). Deal (i) is sealed if, when the event begins, the two people with badge (i) are on adjacent vertices. Each sealed deal contributes (w_i) to your earnings. Before the event starts, you are allowed one reshuffle: Choose any (potentially empty) set of edges such that no two chosen edges share a vertex (i.e., the edges form a matching). For every chosen edge ((u, v)), swap the people at vertices (u) and (v). After reshuffling, what is the maximum you can earn from this event? 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 single integer (n) ((1 \leq n \leq 10^5)). The next line contains (n) integers (w_1, w_2, \ldots, w_n) ((0 \leq w_i \leq 10^5)), where (w_i) denotes the profit from deal (i). The next line contains (2n) integers (a_1, a_2, \ldots, a_{2n}). It is guaranteed that each value (1, 2, \ldots, n) appears exactly twice in (a). The next (2n-1) lines each contain two integers (u) and (v) ((1 \leq u, v, \leq 2n, u \neq v)) — denoting that an edge connects nodes (u) and (v). It is guaranteed that the sum of (n) over all test cases does not exceed (10^5). For each test case, output a single integer — the maximum total earning after a reshuffle. Test 1. Swap edges ((1,2)) and ((3,4)) (they don't share vertices). Then the two 1s become adjacent on edge ((2,3)), earni |
| Tutorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 370213186 | rlakkh | H | April 8, 2026, 1:24 a.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 406 | 20582400 | ||
| 370213093 | _annhien_ruby22 | H | April 8, 2026, 1:22 a.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 437 | 28160000 | ||
| 370167842 | Musa_82FaGm | H | April 7, 2026, 3:57 p.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 468 | 28262400 | ||
| 370180997 | bnnpuu | H | April 7, 2026, 4:38 p.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 546 | 26828800 | ||
| 370181316 | TheAkback | H | April 7, 2026, 4:40 p.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 609 | 49254400 | ||
| 370184641 | PlayVoltz | H | April 7, 2026, 4:49 p.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 609 | 73830400 | ||
| 370181036 | hritikroshansingh | H | April 7, 2026, 4:39 p.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 640 | 36659200 | ||
| 370206211 | Kolya | H | April 7, 2026, 9:35 p.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 781 | 68505600 | ||
| 370184483 | lyfdxh | H | April 7, 2026, 4:49 p.m. | OK | C++17 (GCC 7-32) | TESTS | 67 | 1062 | 35635200 | ||
| 370223056 | Hongruizhao | H | April 8, 2026, 4:48 a.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 359 | 85094400 | ||
| 370180970 | TKT_YI | H | April 7, 2026, 4:38 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 390 | 70451200 | ||
| 370184331 | kotatsugame | H | April 7, 2026, 4:49 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 390 | 70758400 | ||
| 370183743 | sambhavdwivediofficial | H | April 7, 2026, 4:47 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 421 | 40652800 | ||
| 370208975 | DylanSmith | H | April 7, 2026, 11:07 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 468 | 54784000 | ||
| 370176881 | ji_114514 | H | April 7, 2026, 4:24 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 468 | 73216000 | ||
| 370189009 | kotatsugame | H | April 7, 2026, 5:42 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 468 | 77107200 | ||
| 370179047 | Pushanka | H | April 7, 2026, 4:31 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 484 | 108748800 | ||
| 370179055 | BucketPotato | H | April 7, 2026, 4:32 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 500 | 83456000 | ||
| 370198628 | onlyfn | H | April 7, 2026, 7:22 p.m. | OK | C++20 (GCC 13-64) | TESTS | 67 | 531 | 97689600 | ||
| 370183352 | woyebuzhidaowoshishui | H | April 7, 2026, 4:46 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 343 | 90521600 | ||
| 370168168 | 1forest1 | H | April 7, 2026, 3:58 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 359 | 24576000 | ||
| 370203547 | CharlieKirk | H | April 7, 2026, 8:40 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 359 | 34918400 | ||
| 370194734 | zwezdinv | H | April 7, 2026, 6:36 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 359 | 63385600 | ||
| 370176588 | adam.jq.xu | H | April 7, 2026, 4:23 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 390 | 60211200 | ||
| 370210616 | masy2011 | H | April 8, 2026, 12:17 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 390 | 63897600 | ||
| 370181193 | Nachia | H | April 7, 2026, 4:39 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 406 | 58982400 | ||
| 370219984 | Misaka16172 | H | April 8, 2026, 3:53 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 421 | 51404800 | ||
| 370175254 | A_G | H | April 7, 2026, 4:19 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 453 | 106496000 | ||
| 370173390 | El_Matador55 | H | April 7, 2026, 4:13 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 67 | 484 | 69632000 |
Back to search problems