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 consisting of n vertices. Recall that a tree is an undirected connected acyclic graph. The given tree is rooted at the vertex 1 . You have to process q queries. In each query, you are given a vertex of the tree v and an integer k . To process a query, you may delete any vertices from the tree in any order, except for the root and the vertex v . When a vertex is deleted, its children become the children of its parent. You have to process a query in such a way that maximizes the value of c(v) - m cdot k (where c(v) is the resulting number of children of the vertex v , and m is the number of vertices you have deleted). Print the maximum possible value you can obtain. The queries are independent: the changes you make to the tree while processing a query don't affect the tree in other queries. The first line contains one integer n ( 1 <= n <= 2 cdot 10^5 ) -- the number of vertices in the tree. Then n-1 lines follow, the i -th of them contains two integers x_i and y_i ( 1 <= x_i, y_i <= n ; x_i ne y_i ) -- the endpoints of the i -th edge. These edges form a tree. The next line contains one integer q ( 1 <= q <= 2 cdot 10^5 ) -- the number of queries. Then q lines follow, the j -th of them contains two integers v_j and k_j ( 1 <= v_j <= n ; 0 <= k_j <= 2 cdot 10^5 ) -- the parameters of the j -th query. For each query, print one integer -- the maximum value of c(v) - m cdot k you can achieve. The tree in the first example is shown in the following picture: Answers to the queries are obtained as follows: "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
133523402 |
rainboy |
F |
Oct. 29, 2021, 4:50 p.m. |
OK |
GNU C11 |
TESTS |
75 |
998 |
35532800 |
|
|
133522534 |
rainboy |
F |
Oct. 29, 2021, 4:45 p.m. |
OK |
GNU C11 |
TESTS |
75 |
998 |
35532800 |
|
|
133558306 |
19ty02 |
F |
Oct. 30, 2021, 3:11 a.m. |
OK |
GNU C++14 |
TESTS |
75 |
171 |
47104000 |
|
|
133523613 |
rainboy |
F |
Oct. 29, 2021, 4:51 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
265 |
38912000 |
|
|
133557603 |
19ty02 |
F |
Oct. 30, 2021, 2:55 a.m. |
OK |
GNU C++14 |
TESTS |
75 |
280 |
33280000 |
|
|
133526949 |
rainboy |
F |
Oct. 29, 2021, 5:19 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
295 |
38912000 |
|
|
133527080 |
rainboy |
F |
Oct. 29, 2021, 5:20 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
296 |
32870400 |
|
|
133526966 |
rainboy |
F |
Oct. 29, 2021, 5:19 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
311 |
38912000 |
|
|
133526931 |
rainboy |
F |
Oct. 29, 2021, 5:18 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
312 |
38912000 |
|
|
133516709 |
eecs |
F |
Oct. 29, 2021, 4:25 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
514 |
429977600 |
|
|
133516127 |
eecs |
F |
Oct. 29, 2021, 4:23 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
530 |
526131200 |
|
|
133520516 |
SkyCrystal |
F |
Oct. 29, 2021, 4:34 p.m. |
OK |
GNU C++14 |
TESTS |
75 |
686 |
499609600 |
|
|
133515497 |
ysysys |
F |
Oct. 29, 2021, 4:22 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
311 |
35225600 |
|
|
133557497 |
cbr.2 |
F |
Oct. 30, 2021, 2:53 a.m. |
OK |
GNU C++17 |
TESTS |
75 |
529 |
28467200 |
|
|
133524070 |
nomanhasan123 |
F |
Oct. 29, 2021, 4:55 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
561 |
38502400 |
|
|
133523806 |
magnirostris |
F |
Oct. 29, 2021, 4:53 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
780 |
356761600 |
|
|
133526102 |
geospiza |
F |
Oct. 29, 2021, 5:11 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
780 |
356761600 |
|
|
133548450 |
_overrated_ |
F |
Oct. 29, 2021, 10:40 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
795 |
75264000 |
|
|
133548467 |
_overrated_ |
F |
Oct. 29, 2021, 10:41 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
873 |
62464000 |
|
|
133558237 |
northbank |
F |
Oct. 30, 2021, 3:09 a.m. |
OK |
GNU C++17 |
TESTS |
75 |
1123 |
390553600 |
|
|
133536597 |
lucaperju |
F |
Oct. 29, 2021, 6:56 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
1169 |
429363200 |
|
|
133523906 |
hank55663 |
F |
Oct. 29, 2021, 4:54 p.m. |
OK |
GNU C++17 |
TESTS |
75 |
1216 |
299417600 |
|
|
133557212 |
mrsrz |
F |
Oct. 30, 2021, 2:47 a.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
202 |
57036800 |
|
|
133527101 |
rainboy |
F |
Oct. 29, 2021, 5:20 p.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
280 |
47411200 |
|
|
133524113 |
Fulisike |
F |
Oct. 29, 2021, 4:55 p.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
389 |
50892800 |
|
|
133516889 |
m_99 |
F |
Oct. 29, 2021, 4:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
405 |
42700800 |
|
|
133566058 |
teacherhsy |
F |
Oct. 30, 2021, 5:29 a.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
577 |
155238400 |
|
|
133545359 |
SampsonYW |
F |
Oct. 29, 2021, 9:14 p.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
685 |
390860800 |
|
|
133559201 |
tomato_potato |
F |
Oct. 30, 2021, 3:29 a.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
686 |
68812800 |
|
|
133521894 |
Andreasyan |
F |
Oct. 29, 2021, 4:41 p.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
686 |
385228800 |
|
|
133525150 |
Iscream2001 |
F |
Oct. 29, 2021, 5:03 p.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
717 |
94208000 |
|
|
133518442 |
sorry_sorry_thebighead |
F |
Oct. 29, 2021, 4:29 p.m. |
OK |
GNU C++17 (64) |
TESTS |
75 |
717 |
390860800 |
|
|
133512997 |
Nero |
F |
Oct. 29, 2021, 4:15 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
312 |
33792000 |
|
|
133524236 |
Golovanov399 |
F |
Oct. 29, 2021, 4:56 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
421 |
74035200 |
|
|
133534301 |
WildHamburger |
F |
Oct. 29, 2021, 6:28 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
841 |
78131200 |
|
|
133527121 |
rainboy |
F |
Oct. 29, 2021, 5:20 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
935 |
47411200 |
|
|
133546143 |
Bench0310 |
F |
Oct. 29, 2021, 9:34 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
1014 |
399667200 |
|
|
133546415 |
Bench0310 |
F |
Oct. 29, 2021, 9:40 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
1044 |
399667200 |
|
|
133546286 |
Bench0310 |
F |
Oct. 29, 2021, 9:37 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
1075 |
399667200 |
|
|
133546229 |
Bench0310 |
F |
Oct. 29, 2021, 9:35 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
1107 |
439705600 |
|
|
133546216 |
Bench0310 |
F |
Oct. 29, 2021, 9:35 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
1138 |
439705600 |
|
|
133546196 |
Bench0310 |
F |
Oct. 29, 2021, 9:35 p.m. |
OK |
GNU C++20 (64) |
TESTS |
75 |
1154 |
497459200 |
|
|
remove filters
Back to search problems