Codeforces Round 715 (Div. 1)


A. Binary Literature
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1
00
11
01
3
011001
111010
010001
Output
010
011001010
----------------------------------------------------------------------------------------------------
B. Almost Sorted
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
4 4
2 1 14
1 4 14
3 2 15
4 3 8
Output
15
Input
6 6
3 6 4
2 4 1
4 5 7
3 4 10
3 5 1
5 2 15
Output
0
Input
5 6
2 3 11
5 3 7
1 4 10
2 4 14
4 3 8
2 5 6
Output
6
----------------------------------------------------------------------------------------------------
D. Swap Pass
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
-1 -2 2
3 0 5
1 3 4
4 -3 3
5 2 1
Output
5
1 2
5 3
4 5
1 5
1 3
Input
3
5 4 1
0 0 2
-3 -2 3
Output
0
----------------------------------------------------------------------------------------------------
E. Tree Calendar
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
4 5 2 1 7 6 3
1 5
7 6
1 2
2 7
3 4
1 3
Output
YES
5
1 4 2 3 7 6 5
Input
7
7 6 5 3 1 4 2
4 3
2 5
3 7
1 4
7 2
2 6
Output
NO
----------------------------------------------------------------------------------------------------
F. Optimal Encoding
time limit per test: 7 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4 3
2 4 1 3
1 3
2 4
1 4
Output
2
4
3
Input
8 4
3 7 4 8 1 5 2 6
3 6
1 6
3 8
1 8
Output
3
5
9
7
Input
10 10
10 5 1 2 7 3 9 4 6 8
2 2
4 5
6 8
4 10
4 4
2 7
2 2
7 8
3 7
2 10
Output
0
1
3
6
6
9
9
9
9
8
----------------------------------------------------------------------------------------------------
