Codeforces Round 647 (Div. 1) - Thanks, Algo Muse!


A. Johnny and Contribution
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2
2 3
3 1
2 1 3
Output
2 1 3
Input
3 3
1 2
2 3
3 1
1 1 1
Output
-1
Input
5 3
1 2
2 3
4 5
2 1 2 2 1
Output
2 5 1 3 4
----------------------------------------------------------------------------------------------------
B. Johnny and Grandmaster
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 2
2 3 4 4 3
3 1
2 10 1000
4 5
0 1 1 100
1 8
89
Output
4
1
146981438
747093407
----------------------------------------------------------------------------------------------------
C. Johnny and Megan's Necklace
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
13 11
11 1
3 5
17 1
9 27
Output
3
8 7 9 10 5 6 1 2 3 4 
Input
5
13 11
11 1
3 5
17 1
7 29
Output
2
8 7 10 9 5 6 4 3 2 1 
Input
1
1 1
Output
20
2 1 
----------------------------------------------------------------------------------------------------
D. Johnny and James
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 2
0 0
1 1
2 2
3 3
0 1
0 2
Output
6.24264069
Input
6 5
0 0
1 1
2 2
3 3
0 1
0 2
Output
32.62741700
Input
13 10
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
0 -2
0 1
0 2
Output
237.00000000
Input
10 5
2 2
4 4
3 5
6 10
0 5
0 0
5 0
10 0
0 10
4 7
Output
181.52406315
----------------------------------------------------------------------------------------------------
E. James and the Chase
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 3
1 2
2 3
3 1
3 6
1 2
2 1
2 3
3 2
1 3
3 1
7 10
1 2
2 3
3 1
1 4
4 5
5 1
4 6
6 7
7 4
6 1
6 8
1 2
2 3
3 4
4 5
5 6
6 1
6 2
5 1
Output
1 2 3 
-1
1 2 3 5 
-1
----------------------------------------------------------------------------------------------------
F. Johnny and New Toy
time limit per test: 15 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

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