Codeforces Round 1035 (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
2119 Codeforces Round 1035 (Div. 2) FINISHED False 7200 24679522 July 5, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 169 ) F Volcanic Eruptions PROGRAMMING dfs and similar dp

There is an undirected tree with root (1) where each vertex has a weight (w_i\in\{1,-1\}). A volcano at the root erupts at time (0). At time (t), lava floods all vertices whose distance from the root is at most (t), where the distance is the number of edges in the shortest path between the two vertices. At time (0), you are at vertex (st) with life value (S), initially (S=1). Starting at time (0) (including time (0)), the following events happen in order at each time stamp: Let (u) be the vertex you are currently at. Your life value increases by (w_u), i.e., (S\gets S+w_u). If (S=0) or if vertex (u) is flooded with lava at this time, you die immediately. You must move to an adjacent vertex (includes father and sons; staying in place is not allowed). You arrive at the chosen vertex at the next time stamp. Find the maximum number of moves you can make before you die. 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. For each test case, the first line contains two integers (n,st) ((2 \le st \le n \le 5\cdot 10^5)), denoting the number of vertices and the vertex you start at at time stamp (0). The second line contains (n) integers (w_1, w_2, \ldots, w_n) ((w_i\in\{1,-1\}),(w_{st}=1)), where (w_i) represents the weight of the vertex (i). The next (n-1) lines each contain two integers (u,v) ((1\le u,v \le n)), which describe a pair of vertices connected by an edge. It is guaranteed that the given graph is a tree and the sum of (n) over all test cases does not exceed (10^6). For each test case, output a line with an integer indicating the maximum number of moves you can make. Here is a picture that shows the tree in the first test case. One of the optimal sequence of moves is (4\to3\to4\to5\to6\to7\to6), which makes (6) mov

Tutorials

Codeforces Round 1035 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
327639613 ayushkumar991890 F July 5, 2025, 7:06 p.m. OK C++17 (GCC 7-32) TESTS 55 1218 30720000
327618737 potato167 F July 5, 2025, 4:27 p.m. OK C++17 (GCC 7-32) TESTS 55 1265 30720000
327655811 Anfelesan F July 6, 2025, 12:08 a.m. OK C++17 (GCC 7-32) TESTS 55 2343 93593600
327655722 Anleonsa F July 6, 2025, 12:04 a.m. OK C++17 (GCC 7-32) TESTS 55 2343 93593600
327629959 111445 F July 5, 2025, 5:43 p.m. OK C++20 (GCC 13-64) TESTS 55 858 24371200
327629698 111445 F July 5, 2025, 5:41 p.m. OK C++20 (GCC 13-64) TESTS 55 858 24371200
327645615 kaiboy F July 5, 2025, 8:12 p.m. OK C++20 (GCC 13-64) TESTS 55 1093 32051200
327655696 thisislike_fan F July 6, 2025, 12:04 a.m. OK C++20 (GCC 13-64) TESTS 55 1702 115712000
327666720 zac2010 F July 6, 2025, 4:03 a.m. OK C++20 (GCC 13-64) TESTS 55 2124 30822400
327670179 zac2010 F July 6, 2025, 4:59 a.m. OK C++20 (GCC 13-64) TESTS 55 2155 30822400
327670501 xuziyang2010 F July 6, 2025, 5:04 a.m. OK C++20 (GCC 13-64) TESTS 55 2187 30822400
327670343 xuziyang2010 F July 6, 2025, 5:02 a.m. OK C++20 (GCC 13-64) TESTS 55 2187 30822400
327666644 zac2010 F July 6, 2025, 4:02 a.m. OK C++20 (GCC 13-64) TESTS 55 2187 30822400
327624410 fogrevelation F July 5, 2025, 5:06 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 1062 33587200
327626646 fogrevelation F July 5, 2025, 5:20 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 1124 33587200
327625913 fogrevelation F July 5, 2025, 5:15 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 1124 33587200
327635412 thisislike F July 5, 2025, 6:28 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 1140 33587200
327627321 fogrevelation F July 5, 2025, 5:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 1140 33587200
327651110 maro_7atem365 F July 5, 2025, 9:45 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 1311 33382400
327649330 244mhq F July 5, 2025, 9:07 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 2249 51302400
327624680 maspy F July 5, 2025, 5:07 p.m. OK C++23 (GCC 14-64, msys2) TESTS 55 2718 116633600

remove filters

Back to search problems