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'Santa has an infinite number of candies for each of m flavours. You are given a rooted tree with n vertices. The root of the tree is the vertex 1 . Each vertex contains exactly one candy. The i -th vertex has a candy of flavour f_i . Sometimes Santa fears that candies of flavour k have melted. He chooses any vertex x randomly and sends the subtree of x to the Bakers for a replacement. In a replacement, all the candies with flavour k are replaced with a new candy of the same flavour. The candies which are not of flavour k are left unchanged. After the replacement, the tree is restored. The actual cost of replacing one candy of flavour k is c_k (given for each k ). The Baker keeps the price fixed in order to make calculation simple. Every time when a subtree comes for a replacement, the Baker charges C , no matter which subtree it is and which flavour it is. Suppose that for a given flavour k the probability that Santa chooses a vertex for replacement is same for all the vertices. You need to find out the expected value of error in calculating the cost of replacement of flavour k . The error in calculating the cost is defined as follows. Error E(k) = (Actual Cost xe2 x80 x93 Price charged by the Bakers) ^ 2. Note that the actual cost is the cost of replacement of one candy of the flavour k multiplied by the number of candies in the subtree. Also, sometimes Santa may wish to replace a candy at vertex x with a candy of some flavour from his pocket. You need to handle two types of operations: The first line of the input contains four integers n ( 2 xe2 x80 x89 <= qslant xe2 x80 x89n xe2 x80 x89 <= qslant xe2 x80 x895 cdot 10^4 ), m , q , C ( 1 xe2 x80 x89 <= qslant xe2 x80 x89m, q xe2 x80 x89 <= qslant xe2 x80 x895 cdot 10^4 , 0 <= qslant C <= qslant 10^6 ) -- the number of nodes, total number of different flavours of candies, the number of queries and the price charged by the Bakers '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
38386943 |
Scut82 |
H |
May 18, 2018, 2:44 a.m. |
OK |
GNU C++ |
TESTS |
104 |
264 |
11161600 |
|
3000 |
37092009 |
wxy_z |
H |
April 8, 2018, 8:56 a.m. |
OK |
GNU C++ |
TESTS |
104 |
296 |
299315200 |
|
3000 |
37897891 |
cdgyp |
H |
May 5, 2018, 6:52 a.m. |
OK |
GNU C++ |
TESTS |
104 |
312 |
149708800 |
|
3000 |
37137935 |
XingGeRuCi |
H |
April 10, 2018, 7:20 a.m. |
OK |
GNU C++ |
TESTS |
104 |
327 |
410726400 |
|
3000 |
37119029 |
Panole233 |
H |
April 9, 2018, 10:50 a.m. |
OK |
GNU C++ |
TESTS |
104 |
358 |
328294400 |
|
3000 |
39791242 |
SXnoname |
H |
June 30, 2018, 7:52 a.m. |
OK |
GNU C++ |
TESTS |
104 |
498 |
148480000 |
|
3000 |
39822602 |
ZhongJQ |
H |
July 1, 2018, 1:34 p.m. |
OK |
GNU C++ |
TESTS |
104 |
514 |
329011200 |
|
3000 |
39786947 |
cold_chair |
H |
June 30, 2018, 3:32 a.m. |
OK |
GNU C++ |
TESTS |
104 |
514 |
343040000 |
|
3000 |
39786826 |
ilnil |
H |
June 30, 2018, 3:23 a.m. |
OK |
GNU C++ |
TESTS |
104 |
545 |
124825600 |
|
3000 |
39794123 |
jokerwyt |
H |
June 30, 2018, 10:08 a.m. |
OK |
GNU C++ |
TESTS |
104 |
560 |
402636800 |
|
3000 |
37262486 |
jhdjames37 |
H |
April 13, 2018, 12:50 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
202 |
18227200 |
|
3000 |
47869694 |
Durant_Lee |
H |
Jan. 3, 2019, 12:07 p.m. |
OK |
GNU C++11 |
TESTS |
104 |
217 |
369152000 |
|
3000 |
40932471 |
ReaLNero1 |
H |
July 30, 2018, 1:49 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
218 |
14745600 |
|
3000 |
39011768 |
zhouyuyang |
H |
June 7, 2018, 7:38 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
218 |
312422400 |
|
3000 |
37138755 |
cuizhuyefei |
H |
April 10, 2018, 8:05 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
218 |
498995200 |
|
3000 |
48279387 |
1592063346 |
H |
Jan. 12, 2019, 7:16 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
233 |
427520000 |
|
3000 |
48281173 |
vjudge5 |
H |
Jan. 12, 2019, 8:03 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
234 |
119091200 |
|
3000 |
48281099 |
vjudge4 |
H |
Jan. 12, 2019, 8:01 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
234 |
217292800 |
|
3000 |
48281151 |
vjudge2 |
H |
Jan. 12, 2019, 8:02 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
249 |
126054400 |
|
3000 |
48281030 |
1592063346 |
H |
Jan. 12, 2019, 7:59 a.m. |
OK |
GNU C++11 |
TESTS |
104 |
249 |
287436800 |
|
3000 |
43106909 |
consecutivelimit |
H |
Sept. 20, 2018, 9:12 a.m. |
OK |
GNU C++14 |
TESTS |
104 |
156 |
13926400 |
|
3000 |
59691698 |
Scut82 |
H |
Aug. 30, 2019, 6:26 a.m. |
OK |
GNU C++14 |
TESTS |
104 |
186 |
12595200 |
|
3000 |
37111889 |
apiadu |
H |
April 9, 2018, 1:57 a.m. |
OK |
GNU C++14 |
TESTS |
104 |
249 |
315904000 |
|
3000 |
37108292 |
TadijaSebez |
H |
April 8, 2018, 7:32 p.m. |
OK |
GNU C++14 |
TESTS |
104 |
264 |
366182400 |
|
3000 |
52810189 |
Christopher_Liu |
H |
April 16, 2019, 8:06 a.m. |
OK |
GNU C++14 |
TESTS |
104 |
280 |
325427200 |
|
3000 |
37076939 |
MiFaFaOvO |
H |
April 7, 2018, 6:16 p.m. |
OK |
GNU C++14 |
TESTS |
104 |
280 |
498176000 |
|
3000 |
50730067 |
hychyc |
H |
March 3, 2019, 11 a.m. |
OK |
GNU C++14 |
TESTS |
104 |
311 |
189132800 |
|
3000 |
37124699 |
_KEKC_ |
H |
April 9, 2018, 2:41 p.m. |
OK |
GNU C++14 |
TESTS |
104 |
311 |
299315200 |
|
3000 |
50486746 |
ctlchild |
H |
Feb. 25, 2019, 11:53 a.m. |
OK |
GNU C++14 |
TESTS |
104 |
311 |
416563200 |
|
3000 |
37114074 |
superguymj |
H |
April 9, 2018, 5:50 a.m. |
OK |
GNU C++14 |
TESTS |
104 |
312 |
249036800 |
|
3000 |
69889250 |
maroonrk |
H |
Jan. 31, 2020, 9:23 a.m. |
OK |
GNU C++17 |
TESTS |
104 |
202 |
19456000 |
|
3000 |
52810228 |
vjudge1 |
H |
April 16, 2019, 8:07 a.m. |
OK |
GNU C++17 |
TESTS |
104 |
311 |
325427200 |
|
3000 |
37545984 |
tamionv |
H |
April 23, 2018, 7:50 a.m. |
OK |
GNU C++17 |
TESTS |
104 |
670 |
504012800 |
|
3000 |
37076112 |
Benq |
H |
April 7, 2018, 6:09 p.m. |
OK |
GNU C++17 |
TESTS |
104 |
717 |
16281600 |
|
3000 |
37541516 |
tamionv |
H |
April 22, 2018, 10:05 p.m. |
OK |
GNU C++17 |
TESTS |
104 |
1013 |
504012800 |
|
3000 |
37541510 |
tamionv |
H |
April 22, 2018, 10:04 p.m. |
OK |
GNU C++17 |
TESTS |
104 |
1044 |
504012800 |
|
3000 |
41996312 |
Roundgod |
H |
Aug. 23, 2018, 12:19 p.m. |
OK |
GNU C++17 |
TESTS |
104 |
3650 |
376012800 |
|
3000 |
37080093 |
eatmore |
H |
April 7, 2018, 7:49 p.m. |
OK |
Java 8 |
TESTS |
104 |
1060 |
134451200 |
|
3000 |
47806092 |
LoneFox |
H |
Jan. 1, 2019, 7:23 a.m. |
OK |
MS C++ |
TESTS |
104 |
499 |
325017600 |
|
3000 |
remove filters
Back to search problems