Codeforces Round 866 (Div. 1)


A. Constructive Problem
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2 1
4
0 2 2 0
4
3 2 0 2
1
0
Output
Yes
Yes
No
No
----------------------------------------------------------------------------------------------------
B. The Butcher
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2
3 5
1 3
3
1 1
1 1
1 1
1
10 10
4
3 2
5 5
2 2
8 7
Output
1
4 5
2
1 3
3 1
1
10 10
1
13 7
----------------------------------------------------------------------------------------------------
C. The Fox and the Complete Tree Traversal
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
1 3
3 4
3 5
Output
Yes
4 5 1 2 3 
Input
3
1 2
1 3
Output
Yes
1 2 3
Input
15
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
5 11
6 12
6 13
7 14
7 15
Output
No
----------------------------------------------------------------------------------------------------
D. Misha and Apples
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 4
2 1 2
2 4 1
2 1 2
4 4
2 1 2
2 3 4
0
1 1
2 5
0
0
5 3
0
3 1 2 3
2 3 1
0
1 3
Output
2
1
5
3
----------------------------------------------------------------------------------------------------
E. Roads in E City
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 2
1 2
2 1
1
0
1
1
3 3
1 2
2 3
3 1
1
1
1
0
1
1
1
1
Output
- 1
? 1
? 2
- 2
+ 1
? 1
! 1 0
- 1
? 2
? 1
- 2
? 3
? 3
+ 1
? 3
? 2
? 1
! 1 1 1
----------------------------------------------------------------------------------------------------
F. Willy-nilly, Crack, Into Release!
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
2 4
aa
ac
dd
ac
Output
2 12
4 4
-1
12 12
Input
3 2
acc
bdd
Output
2 44
28 44
----------------------------------------------------------------------------------------------------
