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.
Problems
B"You are given a tree of n vertices and n - 1 edges. The i -th vertex has an initial weight a_i . Let the distance d_v(u) from vertex v to vertex u be the number of edges on the path from v to u . Note that d_v(u) = d_u(v) and d_v(v) = 0 . Let the weighted distance w_v(u) from v to u be w_v(u) = d_v(u) + a_u . Note that w_v(v) = a_v and w_v(u) neq w_u(v) if a_u neq a_v . Analogically to usual distance, let's define the eccentricity e(v) of vertex v as the greatest weighted distance from v to any other vertex (including v itself), or e(v) = max limits_{1 <= u <= n}{w_v(u)} . Finally, let's define the radius r of the tree as the minimum eccentricity of any vertex, or r = min limits_{1 <= v <= n}{e(v)} . You need to perform m queries of the following form: After performing each query, print the radius r of the current tree. The first line contains the single integer n ( 2 <= n <= 2 cdot 10^5 ) -- the number of vertices in the tree. The second line contains n integers a_1, ... , a_n ( 0 <= a_i <= 10^6 ) -- the initial weights of vertices. Next n - 1 lines contain edges of tree. The i -th line contains two integers u_i and v_i ( 1 <= u_i, v_i <= n ; u_i neq v_i ) -- the corresponding edge. The given edges form a tree. The next line contains the single integer m ( 1 <= m <= 10^5 ) -- the number of queries. Next m lines contain queries -- one query per line. The j -th query contains two integers v_j and x_j ( 1 <= v_j <= n ; 0 <= x_j <= 10^6 ) -- a vertex and it's new weight. Print m integers -- the radius r of the tree after performing each query. After the first query, you have the following tree: The tree after the second query: After the third query, the radiu"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
188522632 |
Moka50 |
G |
Jan. 8, 2023, 8:15 p.m. |
OK |
GNU C11 |
TESTS |
36 |
1419 |
23859200 |
|
|
188537058 |
firepower |
G |
Jan. 9, 2023, 3:18 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
1153 |
90419200 |
|
|
188514207 |
ftt2333 |
G |
Jan. 8, 2023, 6:19 p.m. |
OK |
GNU C++14 |
TESTS |
36 |
1372 |
93798400 |
|
|
188505985 |
ftt2333 |
G |
Jan. 8, 2023, 5:07 p.m. |
OK |
GNU C++14 |
TESTS |
36 |
3493 |
313856000 |
|
|
188535629 |
firepower |
G |
Jan. 9, 2023, 2:46 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
4663 |
181145600 |
|
|
188535743 |
firepower |
G |
Jan. 9, 2023, 2:49 a.m. |
OK |
GNU C++14 |
TESTS |
36 |
4711 |
181145600 |
|
|
188504943 |
ftt2333 |
G |
Jan. 8, 2023, 5 p.m. |
OK |
GNU C++14 |
TESTS |
36 |
5100 |
202752000 |
|
|
188539290 |
Abdulloh55 |
G |
Jan. 9, 2023, 4:03 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
655 |
59289600 |
|
|
188511217 |
Venkat_patel |
G |
Jan. 8, 2023, 5:51 p.m. |
OK |
GNU C++17 |
TESTS |
36 |
779 |
59904000 |
|
|
188501235 |
Folka |
G |
Jan. 8, 2023, 4:39 p.m. |
OK |
GNU C++17 |
TESTS |
36 |
795 |
59904000 |
|
|
188504152 |
KhaledRabie |
G |
Jan. 8, 2023, 4:55 p.m. |
OK |
GNU C++17 |
TESTS |
36 |
795 |
59904000 |
|
|
188522201 |
Saurabh_7651 |
G |
Jan. 8, 2023, 8:07 p.m. |
OK |
GNU C++17 |
TESTS |
36 |
4976 |
197836800 |
|
|
188526701 |
lunchbox |
G |
Jan. 8, 2023, 9:48 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
967 |
140800000 |
|
|
188526611 |
lunchbox |
G |
Jan. 8, 2023, 9:45 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
998 |
140800000 |
|
|
188544329 |
JoesSR |
G |
Jan. 9, 2023, 5:27 a.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
1263 |
47308800 |
|
|
188536465 |
luogu_bot4 |
G |
Jan. 9, 2023, 3:06 a.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
1419 |
101376000 |
|
|
188518837 |
bmerry |
G |
Jan. 8, 2023, 7:15 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
2495 |
75776000 |
|
|
188545767 |
Cxny |
G |
Jan. 9, 2023, 5:48 a.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
4429 |
43724800 |
|
|
188545547 |
Cxny |
G |
Jan. 9, 2023, 5:46 a.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
4586 |
43724800 |
|
|
188536107 |
wygzgyw |
G |
Jan. 9, 2023, 2:57 a.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
5506 |
56627200 |
|
|
188525350 |
PurpleCrayon |
G |
Jan. 8, 2023, 9:11 p.m. |
OK |
GNU C++17 (64) |
TESTS |
36 |
5802 |
320102400 |
|
|
188541271 |
ShmilyTY |
G |
Jan. 9, 2023, 4:37 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
577 |
161280000 |
|
|
188527457 |
A_G |
G |
Jan. 8, 2023, 10:12 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
623 |
62873600 |
|
|
188543892 |
Crying |
G |
Jan. 9, 2023, 5:20 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
935 |
79769600 |
|
|
188546376 |
BocchiTheRock |
G |
Jan. 9, 2023, 5:56 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
950 |
84582400 |
|
|
188539566 |
CC2021zyz |
G |
Jan. 9, 2023, 4:08 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
951 |
66867200 |
|
|
188527641 |
YouKn0wWho |
G |
Jan. 8, 2023, 10:19 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
998 |
130355200 |
|
|
188546029 |
jucason_xu |
G |
Jan. 9, 2023, 5:52 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
1044 |
69939200 |
|
|
188539417 |
CC2021zyz |
G |
Jan. 9, 2023, 4:06 a.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
1075 |
66867200 |
|
|
188527889 |
zhdanovich |
G |
Jan. 8, 2023, 10:28 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
1091 |
73420800 |
|
|
188511262 |
abc864197532 |
G |
Jan. 8, 2023, 5:51 p.m. |
OK |
GNU C++20 (64) |
TESTS |
36 |
1169 |
270438400 |
|
|
remove filters
Back to search problems