Codeforces Round 429 (Div. 1)


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

Examples
Input
5
7 3 5 3 4
2 1 3 2 3
Output
4 7 3 5 3
Input
7
4 6 5 8 8 2 6
2 1 2 2 1 1 2
Output
2 6 4 5 8 8 6
----------------------------------------------------------------------------------------------------
B. Leha and another game about graph
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3
1 2 4
Output
2
Input
7
5 2 4 2 4 1 1
Output
144
----------------------------------------------------------------------------------------------------
D. Destiny
time limit per test: 2.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 1 2 2
1 3 2
1 4 2
Output
1
-1
Input
5 3
1 2 1 3 2
2 5 3
1 2 3
5 5 2
Output
2
1
2
----------------------------------------------------------------------------------------------------
E. In a Trap
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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