Codeforces Round 875 (Div. 1)


A. Copil Copac Draws Trees
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
6
4 5
1 3
1 2
3 4
1 6
7
5 6
2 4
2 7
1 3
1 2
4 5
Output
2
3
----------------------------------------------------------------------------------------------------
B. The BOSS Can Count Pairs
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
3
2 3 2
3 3 1
8
4 2 8 2 1 2 7 5
3 5 8 8 1 1 6 5
8
4 4 8 8 8 8 8 8
8 8 8 8 8 8 8 8
Output
2
7
1
----------------------------------------------------------------------------------------------------
C. Hyperregular Bracket Strings
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
6 0
5 0
8 1
1 3
10 2
3 4
6 9
1000 3
100 701
200 801
300 901
28 5
1 12
3 20
11 14
4 9
18 19
4 3
1 4
1 4
1 4
Output
5
0
0
4
839415253
140
2
----------------------------------------------------------------------------------------------------
D. Mex Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2
2 3
4
1 2
1 3
1 4
10
1 2
1 3
3 4
3 5
1 6
5 7
2 8
6 9
6 10
1
Output
8
15
96
1
----------------------------------------------------------------------------------------------------
E. Bully Sort
time limit per test: 10 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
8 5
6 2 1 5 3 4 7 8
1 8
2 3
4 7
7 8
3 6
Output
5
6
9
8
7
----------------------------------------------------------------------------------------------------
F. The Third Grace
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
2
2 8
1 5
3 8
78 0 50 0 0 0 0 30
1 6
1 5
0 0 0 0 0 100
Output
108
0
----------------------------------------------------------------------------------------------------
