Codeforces Round 808 (Div. 1)


A. Doremy's IQ
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1
1
2 1
1 2
3 1
1 2 1
4 2
1 4 3 1
5 2
5 1 2 4 3
Output
1
11
110
1110
01111
----------------------------------------------------------------------------------------------------
B. Difference Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
1 10 100
4
4 8 9 13
5
0 0 0 8 13
6
2 4 8 16 32 64
7
0 0 0 0 0 0 0
Output
81
3
1
2
0
----------------------------------------------------------------------------------------------------
C. DFS Trees
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 2
3 5
1 3
3 2
4 2
Output
01111
Input
10 11
1 2
2 5
3 4
4 2
8 1
4 5
10 5
9 5
8 2
5 7
4 6
Output
0011111011
----------------------------------------------------------------------------------------------------
D. Partial Virtual Trees
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 998244353
1 2
2 3
1 4
Output
1 6 6 
Input
7 100000007
1 2
1 3
2 4
2 5
3 6
3 7
Output
1 47 340 854 880 320 
Input
8 1000000007
1 2
2 3
3 4
4 5
5 6
6 7
7 8
Output
1 126 1806 8400 16800 15120 5040 
----------------------------------------------------------------------------------------------------
E. Replace
time limit per test: 1.5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5 6
2 5 4 1 3
4 4
1 5
1 4
3 5
4 5
2 3
Output
-1
0
1
2
3
4
Input
6 3
2 3 4 6 1 2
5 6
2 5
2 3
Output
5
1
3
Input
5 3
3 2 2 4 1
2 5
1 3
1 5
Output
-1
-1
0
----------------------------------------------------------------------------------------------------
F. Bugaboo
time limit per test: 2 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
3 2 1 1
1 1
3 1
4
2 0 123456789
2 1 111111111
1 -1 987654321
3 -1 555555555
Output
1
0
1
2
Input
24 8 5 4
4 4
6 12
8 12
15 11
16 7
20 2
21 9
22 12
13
2 13 11
3 15 12
5 7 13
9 3 14
10 5 15
11 15 16
13 14 17
14 1 18
18 9 19
19 6 20
23 10 21
24 8 22
21 13 23
Output
1
4
9
2
1
0
1
10
11
16
16
0
16
----------------------------------------------------------------------------------------------------
