8VC Venture Cup 2016 - Final Round (Div. 2 Edition)


A. Orchestra
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2 1 1
1 2
Output
4
Input
3 2 3 3
1 1
3 1
2 2
Output
1
Input
3 2 3 2
1 1
3 1
2 2
Output
4
----------------------------------------------------------------------------------------------------
B. Island Puzzle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 0 2
2 0 1
Output
YES
Input
2
1 0
0 1
Output
YES
Input
4
1 2 3 0
0 3 2 1
Output
NO
----------------------------------------------------------------------------------------------------
C. XOR Equation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9 5
Output
4
Input
3 3
Output
2
Input
5 2
Output
0
----------------------------------------------------------------------------------------------------
D. Factory Repairs
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2 2 1 8
1 1 2
1 5 3
1 2 1
2 2
1 4 2
1 3 2
2 1
2 3
Output
3
6
4
Input
5 4 10 1 6
1 1 5
1 5 5
1 3 2
1 5 2
2 1
2 2
Output
7
1
----------------------------------------------------------------------------------------------------
E. Package Delivery
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 4 4
3 5
5 8
6 3
8 4
Output
22
Input
16 5 2
8 2
5 1
Output
-1
----------------------------------------------------------------------------------------------------
F. Preorder Test
time limit per test: 7 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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