Codeforces Round 453 (Div. 1)


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. Weighting a Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
2 2 2
1 2
2 3
1 3
Output
YES
1
1
1
Input
4 3
-1 0 2 1
1 2
2 3
3 4
Output
YES
-1
1
1
Input
6 6
3 5 5 5 1 5
1 4
3 2
4 3
4 5
3 5
5 6
Output
YES
3
5
3
-1
-3
5
Input
4 4
4 4 2 4
1 2
2 3
3 4
4 1
Output
NO
----------------------------------------------------------------------------------------------------
E. Cyclic Cipher
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
1
0
Output
1
1
Input
1
100
81
Output
2
91
109
Input
3
1 1 3
165 185 197
Output
2
-6 -9 -1
8 5 13
----------------------------------------------------------------------------------------------------
