Codeforces Beta Round 88


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

Examples
Input
7 4
2 4 3
1 2 0
2 2 0
1 2 1
4 3 5
1 2 2
4 2 0
Output
9
1
0
7
10
7
5
Input
5 5
1 5 4
1 3 1
1 3 4
3 1 5
4 2 5
Output
12
10
10
8
7
----------------------------------------------------------------------------------------------------
B. Very Interesting Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 10 7
Output
2
Input
4 0 9
Output
1 000000001
----------------------------------------------------------------------------------------------------
C. Cycle
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
00100
10000
01001
11101
11000
Output
1 3 2 
Input
5
01111
00000
01000
01100
01110
Output
-1
----------------------------------------------------------------------------------------------------
D. Not Quick Transformation
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

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