Codeforces Round 453 (Div. 2)


A. Visiting a Friend
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
0 2
2 4
3 5
Output
YES
Input
3 7
0 4
2 5
6 7
Output
NO
----------------------------------------------------------------------------------------------------
B. Coloring a Tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
2
1 1 1
Output
perfect
Input
2
1 2 2
Output
ambiguous
0 1 1 3 3
0 1 1 3 2
----------------------------------------------------------------------------------------------------
D. GCD of Polynomials
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
----------------------------------------------------------------------------------------------------
E. Bipartite Segments
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 6
1 2
2 3
3 1
4 5
5 6
6 4
3
1 3
4 6
1 6
Output
5
5
14
Input
8 9
1 2
2 3
3 1
4 5
5 6
6 7
7 8
8 4
7 2
3
1 8
1 4
3 8
Output
27
8
19
----------------------------------------------------------------------------------------------------
