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
A maze is represented by a tree (an undirected graph, where exactly one way exists between each pair of vertices). In the maze the entrance vertex and the exit vertex are chosen with some probability. The exit from the maze is sought by Deep First Search. If there are several possible ways to move, the move is chosen equiprobably. Consider the following pseudo-code: V ( x ) is the list vertices adjacent to x . The flag array is initially filled as FALSE . DFS initially starts with a parameter of an entrance vertex. When the search is finished , variable count will contain the number of moves. Your task is to count the mathematical expectation of the number of moves one has to do to exit the maze. The first line determines the number of vertices in the graph n ( 1 ≤ n ≤ 10 5 ). The next n - 1 lines contain pairs of integers a i and b i , which show the existence of an edge between a i and b i vertices ( 1 ≤ a i , b i ≤ n ). It is guaranteed that the given graph is a tree. Next n lines contain pairs of non-negative numbers x i and y i , which represent the probability of choosing the i -th vertex as an entrance and exit correspondingly. The probabilities to choose vertex i as an entrance and an exit equal and correspondingly. The sum of all x i and the sum of all y i are positive and do not exceed 10 6 . Print the expectation of the number of moves. The absolute or relative error should not exceed 10 - 9 . In the first sample the entrance vertex is always 1 and the exit vertex is always 2. In the second sample the entrance vertex is always 1 and the exit vertex with the probability of 2/5 will be 2 of with the probability if 3/5 will be 3. The mathematical expectations for the exit vertices 2 and 3 will be equal (symmetrical cases). During the first move one can go to the exit vertex with the probability of 0.5 or to go to a vertex that's not the exit vertex with the probability of 0.5. In the first case the number of moves equals 1, in the second one it equ |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
830913 |
tourist |
E |
Nov. 3, 2011, 4:30 p.m. |
OK |
Delphi |
TESTS |
50 |
60 |
65740800 |
|
2600 |
|
10829797 |
ljz |
E |
April 23, 2015, 12:56 a.m. |
OK |
FPC |
TESTS |
50 |
92 |
11571200 |
|
2600 |
|
911023 |
zanoes |
E |
Nov. 30, 2011, 5:06 a.m. |
OK |
FPC |
TESTS |
50 |
110 |
11571200 |
|
2600 |
|
887119 |
coolinging |
E |
Nov. 23, 2011, 8:11 a.m. |
OK |
FPC |
TESTS |
50 |
130 |
9728000 |
|
2600 |
|
1558971 |
blackapple |
E |
April 17, 2012, 7:13 a.m. |
OK |
FPC |
TESTS |
50 |
160 |
22630400 |
|
2600 |
|
1158023 |
sillycross |
E |
Feb. 8, 2012, 3:43 p.m. |
OK |
FPC |
TESTS |
50 |
190 |
16179200 |
|
2600 |
|
2875461 |
shyoshyohw1 |
E |
Jan. 5, 2013, 3:15 p.m. |
OK |
GNU C++ |
TESTS |
50 |
46 |
4505600 |
|
2600 |
|
2947307 |
Leo_Yu |
E |
Jan. 17, 2013, 5:09 a.m. |
OK |
GNU C++ |
TESTS |
50 |
46 |
9113600 |
|
2600 |
|
2910511 |
dogcpp |
E |
Jan. 13, 2013, 8:54 a.m. |
OK |
GNU C++ |
TESTS |
50 |
46 |
13721600 |
|
2600 |
|
31185085 |
131441373 |
E |
Oct. 10, 2017, 9:04 a.m. |
OK |
GNU C++ |
TESTS |
50 |
60 |
9216000 |
|
2600 |
|
34051526 |
goldgenius |
E |
Jan. 9, 2018, 2:48 p.m. |
OK |
GNU C++ |
TESTS |
50 |
60 |
11878400 |
|
2600 |
|
40992186 |
ReaLNero1 |
E |
July 31, 2018, 1:09 a.m. |
OK |
GNU C++ |
TESTS |
50 |
62 |
4300800 |
|
2600 |
|
35547055 |
szpszp |
E |
Feb. 21, 2018, 12:32 p.m. |
OK |
GNU C++ |
TESTS |
50 |
62 |
9113600 |
|
2600 |
|
25488632 |
xzyxzy |
E |
March 15, 2017, 2:48 a.m. |
OK |
GNU C++ |
TESTS |
50 |
62 |
9318400 |
|
2600 |
|
30532140 |
TimeLimitExceed |
E |
Sept. 20, 2017, 1:30 a.m. |
OK |
GNU C++ |
TESTS |
50 |
62 |
9625600 |
|
2600 |
|
23638592 |
vjudge3 |
E |
Jan. 8, 2017, 12:58 a.m. |
OK |
GNU C++ |
TESTS |
50 |
62 |
11673600 |
|
2600 |
|
2822206 |
bakabakashyoshyo |
E |
Dec. 24, 2012, 12:02 p.m. |
OK |
GNU C++0x |
TESTS |
50 |
31 |
4505600 |
|
2600 |
|
2798094 |
dc. |
E |
Dec. 20, 2012, 11:59 a.m. |
OK |
GNU C++0x |
TESTS |
50 |
156 |
9830400 |
|
2600 |
|
9300969 |
aliasadiiii |
E |
Dec. 29, 2014, 8:08 p.m. |
OK |
GNU C++0x |
TESTS |
50 |
156 |
12697600 |
|
2600 |
|
8998081 |
JayYe |
E |
Dec. 6, 2014, 9:24 a.m. |
OK |
GNU C++0x |
TESTS |
50 |
156 |
13414400 |
|
2600 |
|
7658682 |
delta_4d |
E |
Sept. 1, 2014, 6:20 a.m. |
OK |
GNU C++0x |
TESTS |
50 |
186 |
10752000 |
|
2600 |
|
2655600 |
apia |
E |
Nov. 26, 2012, 2:36 a.m. |
OK |
GNU C++0x |
TESTS |
50 |
187 |
10240000 |
|
2600 |
|
2851169 |
CMHJT |
E |
Dec. 29, 2012, 4:40 a.m. |
OK |
GNU C++0x |
TESTS |
50 |
218 |
9625600 |
|
2600 |
|
2666704 |
llj_bash |
E |
Nov. 27, 2012, 7:19 a.m. |
OK |
GNU C++0x |
TESTS |
50 |
265 |
9830400 |
|
2600 |
|
991305 |
Archon.JK |
E |
Dec. 29, 2011, 8:41 p.m. |
OK |
GNU C++0x |
TESTS |
50 |
300 |
13619200 |
|
2600 |
|
69093750 |
luogu_bot3 |
E |
Jan. 19, 2020, 11:12 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
5632000 |
|
2600 |
|
45262119 |
1043795879 |
E |
Nov. 4, 2018, 2:59 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
5632000 |
|
2600 |
|
45262059 |
luogu_bot1 |
E |
Nov. 4, 2018, 2:56 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
5632000 |
|
2600 |
|
45055650 |
Captain_Paul |
E |
Oct. 29, 2018, 12:37 p.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
8089600 |
|
2600 |
|
68309672 |
vjudge2 |
E |
Jan. 6, 2020, 10:36 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
8396800 |
|
2600 |
|
45062891 |
luogu_bot1 |
E |
Oct. 29, 2018, 3:40 p.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
8704000 |
|
2600 |
|
33141909 |
wfj_2048 |
E |
Dec. 12, 2017, 1:16 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
8908800 |
|
2600 |
|
54784562 |
tyler178 |
E |
May 29, 2019, 2:34 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
9420800 |
|
2600 |
|
30532540 |
Saramanda |
E |
Sept. 20, 2017, 2:04 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
10035200 |
|
2600 |
|
30244637 |
Mr.Mo |
E |
Sept. 10, 2017, 12:10 p.m. |
OK |
GNU C++11 |
TESTS |
50 |
62 |
10035200 |
|
2600 |
|
28070325 |
MogicianLNY |
E |
June 27, 2017, 7:09 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
186 |
6348800 |
|
2600 |
|
42280114 |
Redpojoe |
E |
Aug. 30, 2018, 1:46 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
186 |
7065600 |
|
2600 |
|
41595905 |
MetaBro |
E |
Aug. 14, 2018, 4:48 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
186 |
10342400 |
|
2600 |
|
23671101 |
Ali.Pi |
E |
Jan. 9, 2017, 9:06 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
186 |
12083200 |
|
2600 |
|
66423737 |
ragen |
E |
Dec. 6, 2019, 8:08 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
216 |
9216000 |
|
2600 |
|
66421935 |
BamiTorabi |
E |
Dec. 6, 2019, 7:18 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
218 |
10342400 |
|
2600 |
|
41595695 |
ArshiaDadras |
E |
Aug. 14, 2018, 4:42 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
218 |
10342400 |
|
2600 |
|
59510752 |
vjudge3 |
E |
Aug. 26, 2019, 7:54 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
218 |
10854400 |
|
2600 |
|
59510737 |
vjudge4 |
E |
Aug. 26, 2019, 7:54 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
248 |
10854400 |
|
2600 |
|
22597740 |
SakurakoujiRuna |
E |
Nov. 29, 2016, 12:01 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
248 |
11161600 |
|
2600 |
|
50512659 |
nickluo |
E |
Feb. 26, 2019, 2:58 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
92 |
14438400 |
|
2600 |
|
55301284 |
vjudge3 |
E |
June 8, 2019, 12:09 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
186 |
11980800 |
|
2600 |
|
48438027 |
pishbeenZ |
E |
Jan. 15, 2019, 10:46 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
216 |
10854400 |
|
2600 |
|
54636716 |
AliShahali1382 |
E |
May 25, 2019, 5:25 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
216 |
13107200 |
|
2600 |
|
61347652 |
MinecraftFuns |
E |
Sept. 27, 2019, 6:07 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
218 |
8294400 |
|
2600 |
|
42706624 |
vjudge1 |
E |
Sept. 9, 2018, 1:34 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
218 |
8294400 |
|
2600 |
|
64901619 |
SHOToRSAVARE_KAZEMSHAHR |
E |
Nov. 14, 2019, 7:12 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
218 |
14438400 |
|
2600 |
|
54636363 |
AliShahali1382 |
E |
May 25, 2019, 5:15 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
218 |
15462400 |
|
2600 |
|
44580273 |
q234rty |
E |
Oct. 20, 2018, 8:24 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
248 |
8089600 |
|
2600 |
|
48437474 |
how_to_become_purple |
E |
Jan. 15, 2019, 10:01 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
248 |
11673600 |
|
2600 |
|
2927524 |
uwi |
E |
Jan. 15, 2013, 4:13 p.m. |
OK |
Java 6 |
TESTS |
50 |
125 |
0 |
|
2600 |
|
843597 |
uwi |
E |
Nov. 9, 2011, 4:54 p.m. |
OK |
Java 6 |
TESTS |
50 |
220 |
43110400 |
|
2600 |
|
832611 |
Petr |
E |
Nov. 3, 2011, 7:01 p.m. |
OK |
Java 6 |
TESTS |
50 |
280 |
44544000 |
|
2600 |
|
953911 |
FattyPenguin |
E |
Dec. 13, 2011, 12:12 p.m. |
OK |
Java 6 |
TESTS |
50 |
300 |
43212800 |
|
2600 |
|
1095711 |
Darooha |
E |
Jan. 20, 2012, 1:38 a.m. |
OK |
Java 6 |
TESTS |
50 |
420 |
64307200 |
|
2600 |
|
838085 |
Darooha |
E |
Nov. 6, 2011, 2:58 p.m. |
OK |
Java 6 |
TESTS |
50 |
420 |
64307200 |
|
2600 |
|
2789685 |
qiandichen |
E |
Dec. 18, 2012, 6:11 a.m. |
OK |
Java 7 |
TESTS |
50 |
249 |
204800 |
|
2600 |
|
2789648 |
qiandichen |
E |
Dec. 18, 2012, 5:57 a.m. |
OK |
Java 7 |
TESTS |
50 |
265 |
7680000 |
|
2600 |
|
20307353 |
AlexFetisov |
E |
Aug. 31, 2016, 4:16 p.m. |
OK |
Java 8 |
TESTS |
50 |
374 |
11878400 |
|
2600 |
|
22032368 |
JShinjuro |
E |
Nov. 4, 2016, 11:06 a.m. |
OK |
Java 8 |
TESTS |
50 |
404 |
6041600 |
|
2600 |
|
862705 |
zjut_DD |
E |
Nov. 14, 2011, 5:40 a.m. |
OK |
MS C++ |
TESTS |
50 |
200 |
11571200 |
|
2600 |
|
59507702 |
vjudge3 |
E |
Aug. 26, 2019, 6:48 a.m. |
OK |
MS C++ |
TESTS |
50 |
436 |
5939200 |
|
2600 |
|
962716 |
Saeed_Reza |
E |
Dec. 16, 2011, 10:04 a.m. |
OK |
MS C++ |
TESTS |
50 |
980 |
49561600 |
|
2600 |
remove filters
Back to search problems