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
You have a root tree containing n vertexes. Let's number the tree vertexes with integers from 1 to n . The tree root is in the vertex 1 . Each vertex (except fot the tree root) v has a direct ancestor p v . Also each vertex v has its integer value s v . Your task is to perform following queries: P v u ( u ≠ v ). If u isn't in subtree of v , you must perform the assignment p v = u . Otherwise you must perform assignment p u = v . Note that after this query the graph continues to be a tree consisting of n vertexes. V v t . Perform assignment s v = t . Your task is following. Before starting performing queries and after each query you have to calculate expected value written on the lowest common ancestor of two equiprobably selected vertices i and j . Here lowest common ancestor of i and j is the deepest vertex that lies on the both of the path from the root to vertex i and the path from the root to vertex j . Please note that the vertices i and j can be the same (in this case their lowest common ancestor coincides with them). The first line of the input contains integer n ( 2 ≤ n ≤ 5·10 4 ) — the number of the tree vertexes. The second line contains n - 1 integer p 2 , p 3 , ..., p n ( 1 ≤ p i ≤ n ) — the description of the tree edges. It is guaranteed that those numbers form a tree. The third line contains n integers — s 1 , s 2 , ... s n ( 0 ≤ s i ≤ 10 6 ) — the values written on each vertex of the tree. The next line contains integer q ( 1 ≤ q ≤ 5·10 4 ) — the number of queries. Each of the following q lines contains the description of the query in the format described in the statement. It is guaranteed that query arguments u and v lie between 1 and n . It is guaranteed that argument t in the queries of type V meets limits 0 ≤ t ≤ 10 6 . Print q + 1 number — the corresponding expected values. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9 . Note that in the query P v u if u lies in subtree of v you must perf |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
40987740 |
ReaLNero1 |
E |
July 30, 2018, 9:27 p.m. |
OK |
GNU C++ |
TESTS |
64 |
124 |
8396800 |
|
3200 |
|
26833968 |
xzyxzy |
E |
May 4, 2017, 12:17 p.m. |
OK |
GNU C++ |
TESTS |
64 |
124 |
8396800 |
|
3200 |
|
34399940 |
vjudge2 |
E |
Jan. 21, 2018, 4:19 a.m. |
OK |
GNU C++ |
TESTS |
64 |
124 |
8499200 |
|
3200 |
|
26834030 |
xzyxzy |
E |
May 4, 2017, 12:20 p.m. |
OK |
GNU C++ |
TESTS |
64 |
139 |
8396800 |
|
3200 |
|
34399906 |
vjudge3 |
E |
Jan. 21, 2018, 4:18 a.m. |
OK |
GNU C++ |
TESTS |
64 |
139 |
9420800 |
|
3200 |
|
26896045 |
156001006 |
E |
May 6, 2017, 8:06 a.m. |
OK |
GNU C++ |
TESTS |
64 |
140 |
6758400 |
|
3200 |
|
9017997 |
vjudge4 |
E |
Dec. 8, 2014, 11:59 a.m. |
OK |
GNU C++ |
TESTS |
64 |
140 |
6758400 |
|
3200 |
|
9056419 |
VictorWonder |
E |
Dec. 9, 2014, 8:30 a.m. |
OK |
GNU C++ |
TESTS |
64 |
155 |
7475200 |
|
3200 |
|
13920996 |
130705009 |
E |
Oct. 28, 2015, 6:25 p.m. |
OK |
GNU C++ |
TESTS |
64 |
155 |
10035200 |
|
3200 |
|
17085832 |
RNS_JKS |
E |
April 1, 2016, 7 a.m. |
OK |
GNU C++ |
TESTS |
64 |
155 |
11571200 |
|
3200 |
|
8517513 |
MinakoKojima |
E |
Nov. 1, 2014, 8:04 p.m. |
OK |
GNU C++0x |
TESTS |
64 |
156 |
11059200 |
|
3200 |
|
8432345 |
Nero |
E |
Oct. 27, 2014, 1:38 p.m. |
OK |
GNU C++0x |
TESTS |
64 |
171 |
6348800 |
|
3200 |
|
8448379 |
MinakoKojima |
E |
Oct. 28, 2014, 10:39 a.m. |
OK |
GNU C++0x |
TESTS |
64 |
171 |
9420800 |
|
3200 |
|
8520268 |
zhj |
E |
Nov. 2, 2014, 6:38 a.m. |
OK |
GNU C++0x |
TESTS |
64 |
171 |
11264000 |
|
3200 |
|
8448718 |
MinakoKojima |
E |
Oct. 28, 2014, 11:21 a.m. |
OK |
GNU C++0x |
TESTS |
64 |
186 |
9420800 |
|
3200 |
|
8448812 |
MinakoKojima |
E |
Oct. 28, 2014, 11:32 a.m. |
OK |
GNU C++0x |
TESTS |
64 |
202 |
9420800 |
|
3200 |
|
8750934 |
yummy |
E |
Nov. 18, 2014, 10:45 p.m. |
OK |
GNU C++0x |
TESTS |
64 |
467 |
4915200 |
|
3200 |
|
8750818 |
yummy |
E |
Nov. 18, 2014, 10:19 p.m. |
OK |
GNU C++0x |
TESTS |
64 |
701 |
4812800 |
|
3200 |
|
8750826 |
yummy |
E |
Nov. 18, 2014, 10:21 p.m. |
OK |
GNU C++0x |
TESTS |
64 |
717 |
4812800 |
|
3200 |
|
8523992 |
Los_Angelos_Laycurse |
E |
Nov. 2, 2014, 2:04 p.m. |
OK |
GNU C++0x |
TESTS |
64 |
920 |
9113600 |
|
3200 |
|
22158091 |
poursoul |
E |
Nov. 11, 2016, 5:36 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
124 |
6860800 |
|
3200 |
|
69527722 |
xay5421 |
E |
Jan. 25, 2020, 3:46 p.m. |
OK |
GNU C++11 |
TESTS |
64 |
124 |
7168000 |
|
3200 |
|
53392281 |
Big_black_jujube |
E |
April 27, 2019, 7:27 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
139 |
6860800 |
|
3200 |
|
53392238 |
Big_black_jujube |
E |
April 27, 2019, 7:26 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
139 |
6860800 |
|
3200 |
|
53392267 |
Big_black_jujube |
E |
April 27, 2019, 7:27 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
140 |
6758400 |
|
3200 |
|
22157917 |
poursoul |
E |
Nov. 11, 2016, 5:03 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
140 |
6758400 |
|
3200 |
|
18957433 |
Chenyao |
E |
July 7, 2016, 8:05 p.m. |
OK |
GNU C++11 |
TESTS |
64 |
140 |
7475200 |
|
3200 |
|
10748784 |
Remilia-Scarlet |
E |
April 17, 2015, 7:51 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
140 |
9011200 |
|
3200 |
|
10748573 |
Remilia-Scarlet |
E |
April 17, 2015, 7:10 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
140 |
9216000 |
|
3200 |
|
57888034 |
lopare |
E |
July 28, 2019, 10:45 a.m. |
OK |
GNU C++11 |
TESTS |
64 |
140 |
10649600 |
|
3200 |
|
68957072 |
TadijaSebez |
E |
Jan. 16, 2020, 8:48 p.m. |
OK |
GNU C++14 |
TESTS |
64 |
171 |
7987200 |
|
3200 |
|
56732297 |
Scut82 |
E |
July 9, 2019, 2:25 a.m. |
OK |
GNU C++14 |
TESTS |
64 |
187 |
6758400 |
|
3200 |
|
33665521 |
FizzyDavid |
E |
Dec. 27, 2017, 9:47 a.m. |
OK |
GNU C++14 |
TESTS |
64 |
234 |
15769600 |
|
3200 |
|
34047735 |
giorgi |
E |
Jan. 9, 2018, 12:04 p.m. |
OK |
GNU C++14 |
TESTS |
64 |
249 |
15769600 |
|
3200 |
|
23409789 |
Ali.Pi |
E |
Dec. 29, 2016, 9:35 p.m. |
OK |
GNU C++14 |
TESTS |
64 |
1840 |
22937600 |
|
3200 |
|
69955559 |
gongsuidashen |
E |
Feb. 1, 2020, 10:03 a.m. |
OK |
GNU C++17 |
TESTS |
64 |
171 |
8806400 |
|
3200 |
|
58517148 |
hqm01 |
E |
Aug. 10, 2019, 1:16 a.m. |
OK |
GNU C++17 |
TESTS |
64 |
234 |
6041600 |
|
3200 |
|
62316662 |
EZOJ |
E |
Oct. 10, 2019, 3:29 p.m. |
OK |
GNU C++17 |
TESTS |
64 |
264 |
160358400 |
|
3200 |
|
61326252 |
ruo |
E |
Sept. 26, 2019, 1:48 p.m. |
OK |
GNU C++17 |
TESTS |
64 |
265 |
6860800 |
|
3200 |
|
61325185 |
ruo |
E |
Sept. 26, 2019, 1:37 p.m. |
OK |
GNU C++17 |
TESTS |
64 |
280 |
6860800 |
|
3200 |
|
20667620 |
mmaxio |
E |
Sept. 16, 2016, 7:30 p.m. |
OK |
Java 8 |
TESTS |
64 |
405 |
0 |
|
3200 |
|
8398621 |
Petr |
E |
Oct. 25, 2014, 6:27 a.m. |
OK |
Java 8 |
TESTS |
64 |
4274 |
18636800 |
|
3200 |
|
8398607 |
Petr |
E |
Oct. 25, 2014, 6:25 a.m. |
OK |
Java 8 |
TESTS |
64 |
5257 |
22323200 |
|
3200 |
|
8398596 |
Petr |
E |
Oct. 25, 2014, 6:23 a.m. |
OK |
Java 8 |
TESTS |
64 |
5990 |
18534400 |
|
3200 |
|
8524204 |
lych123 |
E |
Nov. 2, 2014, 2:23 p.m. |
OK |
MS C++ |
TESTS |
64 |
156 |
5427200 |
|
3200 |
|
8523930 |
Los_Angelos_Laycurse |
E |
Nov. 2, 2014, 2 p.m. |
OK |
MS C++ |
TESTS |
64 |
1044 |
7065600 |
|
3200 |
remove filters
Back to search problems