Codeforces Round 542 [Alex Lopashev Thanks-Round] (Div. 1)


A1. Toy Train (Simplified)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 7
2 4
5 1
2 3
3 4
4 1
5 3
3 5
Output
10 9 10 10 9 
Input
2 3
1 2
1 2
1 2
Output
5 6 
----------------------------------------------------------------------------------------------------
A2. Toy Train
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 7
2 4
5 1
2 3
3 4
4 1
5 3
3 5
Output
10 9 10 10 9 
Input
2 3
1 2
1 2
1 2
Output
5 6 
----------------------------------------------------------------------------------------------------
B. Wrong Answer
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
Output
4
6 -8 7 -42
Input
612
Output
7
30 -12 -99 123 -2 245 -300
----------------------------------------------------------------------------------------------------
C. Morse Code
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1
1
1
Output
1
3
7
Input
5
1
0
1
0
1
Output
1
4
10
22
43
Input
9
1
1
0
0
0
1
1
0
1
Output
1
3
10
24
51
109
213
421
833
----------------------------------------------------------------------------------------------------
D. Isolation
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
1 1 2
Output
3
Input
5 2
1 1 2 1 3
Output
14
Input
5 5
1 2 3 4 5
Output
16
----------------------------------------------------------------------------------------------------
E. Legendary Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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