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'Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. Also, each edge has its own cost. A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last different from v vertex on the path from the root to the vertex v . Children of vertex v are all vertices for which v is the parent. A vertex is a leaf if it has no children. The weighted tree is such a tree that each edge of this tree has some weight. The weight of the path is the sum of edges weights on this path. The weight of the path from the vertex to itself is 0 . You can make a sequence of zero or more moves. On each move, you select an edge and divide its weight by 2 rounding down. More formally, during one move, you choose some edge i and divide its weight by 2 rounding down ( w_i := <= ft lfloor frac{w_i}{2} right rfloor ). Each edge i has an associated cost c_i which is either 1 or 2 coins. Each move with edge i costs c_i coins. Your task is to find the minimum total cost to make the sum of weights of paths from the root to each leaf at most S . In other words, if w(i, j) is the weight of the path from the vertex i to the vertex j , then you have to make sum limits_{v in leaves} w(root, v) <= S , where leaves is the list of all leaves. You have to answer t independent test cases. The first line of the input contains one integer t ( 1 <= t <= 2 cdot 10^4 ) -- the number of test cases. Then t test cases follow. The first line of the test case contains two integers n and S ( 2 <= n <= 10^5; 1 <= S <= 10^{16} ) -- the number of vertices in the tree and the maximum possible sum of weights you have to obtain. The next n-1 lines'... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
91371168 |
WaluntOvO |
E2 |
Aug. 30, 2020, 3:03 p.m. |
OK |
GNU C++11 |
TESTS |
41 |
249 |
83763200 |
|
|
90473319 |
izumiQR |
E2 |
Aug. 20, 2020, 2:54 p.m. |
OK |
GNU C++11 |
TESTS |
41 |
265 |
22528000 |
|
|
90518821 |
izumiQR |
E2 |
Aug. 21, 2020, 9:20 a.m. |
OK |
GNU C++11 |
TESTS |
41 |
265 |
28979200 |
|
|
90518727 |
izumiQR |
E2 |
Aug. 21, 2020, 9:19 a.m. |
OK |
GNU C++11 |
TESTS |
41 |
265 |
28979200 |
|
|
90518614 |
izumiQR |
E2 |
Aug. 21, 2020, 9:17 a.m. |
OK |
GNU C++11 |
TESTS |
41 |
265 |
28979200 |
|
|
90518910 |
izumiQR |
E2 |
Aug. 21, 2020, 9:22 a.m. |
OK |
GNU C++11 |
TESTS |
41 |
280 |
28979200 |
|
|
91495019 |
ShadyPi |
E2 |
Aug. 31, 2020, 1:31 p.m. |
OK |
GNU C++11 |
TESTS |
41 |
327 |
51609600 |
|
|
91494926 |
KalznAsawind |
E2 |
Aug. 31, 2020, 1:30 p.m. |
OK |
GNU C++11 |
TESTS |
41 |
327 |
115404800 |
|
|
91495662 |
KalznAsawind |
E2 |
Aug. 31, 2020, 1:39 p.m. |
OK |
GNU C++11 |
TESTS |
41 |
342 |
115404800 |
|
|
91499439 |
ShadyPi |
E2 |
Aug. 31, 2020, 2:25 p.m. |
OK |
GNU C++11 |
TESTS |
41 |
343 |
51609600 |
|
|
91569526 |
oipotato |
E2 |
Sept. 1, 2020, 1:31 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
280 |
46489600 |
|
|
90003903 |
K0u1e |
E2 |
Aug. 15, 2020, 8:59 a.m. |
OK |
GNU C++14 |
TESTS |
41 |
296 |
42496000 |
|
|
90321571 |
rfpermen |
E2 |
Aug. 18, 2020, 3:19 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
327 |
185036800 |
|
|
91081150 |
jakubfedak |
E2 |
Aug. 26, 2020, 5:45 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
373 |
16076800 |
|
|
90395939 |
testing_123 |
E2 |
Aug. 19, 2020, 2:16 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
389 |
70758400 |
|
|
90040485 |
xwd456 |
E2 |
Aug. 15, 2020, 6:26 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
421 |
115404800 |
|
|
90041443 |
xwd456 |
E2 |
Aug. 15, 2020, 6:47 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
436 |
120012800 |
|
|
90040787 |
xwd456 |
E2 |
Aug. 15, 2020, 6:32 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
451 |
120012800 |
|
|
90040454 |
xwd456 |
E2 |
Aug. 15, 2020, 6:25 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
452 |
159539200 |
|
|
90697683 |
Zoli9 |
E2 |
Aug. 22, 2020, 3:02 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
468 |
25804800 |
|
|
90735529 |
thebesttv |
E2 |
Aug. 23, 2020, 7:34 a.m. |
OK |
GNU C++17 |
TESTS |
41 |
264 |
23347200 |
|
|
90833835 |
segmentfault |
E2 |
Aug. 24, 2020, 2:23 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
280 |
20480000 |
|
|
90833554 |
vjudge4 |
E2 |
Aug. 24, 2020, 2:19 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
280 |
20889600 |
|
|
90084486 |
wawcac |
E2 |
Aug. 16, 2020, 1:20 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
280 |
23244800 |
|
|
90052750 |
Chanyuh |
E2 |
Aug. 16, 2020, 2:34 a.m. |
OK |
GNU C++17 |
TESTS |
41 |
280 |
41574400 |
|
|
91223328 |
lxk |
E2 |
Aug. 28, 2020, 3:37 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
296 |
45568000 |
|
|
90264424 |
zakhar0 |
E2 |
Aug. 17, 2020, 9:35 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
311 |
47411200 |
|
|
90795009 |
bry_rp |
E2 |
Aug. 24, 2020, 4:37 a.m. |
OK |
GNU C++17 |
TESTS |
41 |
343 |
46694400 |
|
|
90229280 |
Clouder0 |
E2 |
Aug. 17, 2020, 12:53 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
343 |
64512000 |
|
|
90361235 |
wish2lucky |
E2 |
Aug. 19, 2020, 6 a.m. |
OK |
GNU C++17 |
TESTS |
41 |
358 |
72089600 |
|
|
90202706 |
tanzilidrisi68 |
E2 |
Aug. 17, 2020, 7:02 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
233 |
49356800 |
|
|
91690014 |
clearlove20 |
E2 |
Sept. 3, 2020, 5:44 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
249 |
44646400 |
|
|
91257381 |
kunaltawatia |
E2 |
Aug. 29, 2020, 5:19 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
265 |
59187200 |
|
|
91572555 |
WiwiHo |
E2 |
Sept. 1, 2020, 2:10 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
280 |
63795200 |
|
|
90446251 |
dynam1c |
E2 |
Aug. 20, 2020, 8:30 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
311 |
50585600 |
|
|
91648532 |
sirearsh |
E2 |
Sept. 2, 2020, 2:18 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
312 |
50585600 |
|
|
91678451 |
Phortox |
E2 |
Sept. 2, 2020, 11:41 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
312 |
77516800 |
|
|
90002234 |
wangancf |
E2 |
Aug. 15, 2020, 8:38 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
342 |
30924800 |
|
|
91471834 |
sirearsh |
E2 |
Aug. 31, 2020, 8:13 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
373 |
54886400 |
|
|
90054648 |
harshit15 |
E2 |
Aug. 16, 2020, 3:41 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
389 |
51404800 |
|
|
90873736 |
Justyo |
E2 |
Aug. 25, 2020, 6:29 a.m. |
OK |
Java 11 |
TESTS |
41 |
2511 |
191795200 |
|
|
90358037 |
skittles1412 |
E2 |
Aug. 19, 2020, 5 a.m. |
OK |
Java 11 |
TESTS |
41 |
2916 |
202240000 |
|
|
90437409 |
yaoct |
E2 |
Aug. 20, 2020, 6:17 a.m. |
OK |
Java 8 |
TESTS |
41 |
1170 |
111923200 |
|
|
91098328 |
jxin31415 |
E2 |
Aug. 27, 2020, 2:33 a.m. |
OK |
Java 8 |
TESTS |
41 |
1262 |
172544000 |
|
|
91263335 |
BlinKer |
E2 |
Aug. 29, 2020, 7:07 a.m. |
OK |
Java 8 |
TESTS |
41 |
1294 |
25292800 |
|
|
91263649 |
BlinKer |
E2 |
Aug. 29, 2020, 7:12 a.m. |
OK |
Java 8 |
TESTS |
41 |
1309 |
25292800 |
|
|
90520647 |
lansergecs |
E2 |
Aug. 21, 2020, 9:48 a.m. |
OK |
Java 8 |
TESTS |
41 |
1450 |
39321600 |
|
|
90633105 |
AnandOza |
E2 |
Aug. 21, 2020, 7:25 p.m. |
OK |
Java 8 |
TESTS |
41 |
1450 |
107622400 |
|
|
90697173 |
Juniper |
E2 |
Aug. 22, 2020, 2:55 p.m. |
OK |
Java 8 |
TESTS |
41 |
1871 |
126259200 |
|
|
90696628 |
vjudge2 |
E2 |
Aug. 22, 2020, 2:48 p.m. |
OK |
Java 8 |
TESTS |
41 |
2074 |
126259200 |
|
|
90697120 |
vjudge3 |
E2 |
Aug. 22, 2020, 2:55 p.m. |
OK |
Java 8 |
TESTS |
41 |
2090 |
126259200 |
|
|
90036788 |
gazaan |
E2 |
Aug. 15, 2020, 5:11 p.m. |
OK |
Java 8 |
TESTS |
41 |
2979 |
84070400 |
|
|
90432572 |
lee92605 |
E2 |
Aug. 20, 2020, 4:42 a.m. |
OK |
MS C++ 2017 |
TESTS |
41 |
577 |
49049600 |
|
|
91011104 |
wei.youmn |
E2 |
Aug. 26, 2020, 2:32 a.m. |
OK |
MS C++ 2017 |
TESTS |
41 |
998 |
44339200 |
|
|
90294972 |
Wenbo888 |
E2 |
Aug. 18, 2020, 9:37 a.m. |
OK |
PyPy 3 |
TESTS |
41 |
2729 |
85401600 |
|
|
90373135 |
chinerist |
E2 |
Aug. 19, 2020, 8:54 a.m. |
OK |
PyPy 3 |
TESTS |
41 |
2995 |
168550400 |
|
|
90298383 |
dare_not_2 |
E2 |
Aug. 18, 2020, 10:27 a.m. |
OK |
Python 3 |
TESTS |
41 |
2588 |
171212800 |
|
|
remove filters
Back to search problems