Codeforces Round 395 (Div. 1)


A. Timofey and a tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2
2 3
3 4
1 2 1 1
Output
YES
2
Input
3
1 2
2 3
1 2 3
Output
YES
2
Input
4
1 2
2 3
3 4
1 2 1 2
Output
NO
----------------------------------------------------------------------------------------------------
B. Timofey and rectangles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1
----------------------------------------------------------------------------------------------------
C. Timofey and remoduling
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
17 5
0 2 4 13 15
Output
13 2
Input
17 5
0 2 4 13 14
Output
-1
Input
5 3
1 2 3
Output
3 4
----------------------------------------------------------------------------------------------------
D. Timofey and a flat tree
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2
2 3
Output
1
Input
7
1 2
4 2
2 3
5 6
6 7
3 7
Output
1
Input
10
1 7
1 8
9 4
5 1
9 2
3 5
10 6
10 9
5 10
Output
2
----------------------------------------------------------------------------------------------------
E. Timofey and our friends animals
time limit per test: 7 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
3
1 3
2 3
4 5
5
1 1
1 2
2 3
1 3
1 5
Output
1
2
1
1
2
----------------------------------------------------------------------------------------------------
