Codeforces Round 572 (Div. 1)


A1. Add on a Tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
YES
Input
3
1 2
2 3
Output
NO
Input
5
1 2
1 3
1 4
2 5
Output
NO
Input
6
1 2
1 3
1 4
2 5
2 6
Output
YES
----------------------------------------------------------------------------------------------------
A2. Add on a Tree: Revolution
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2
2 3 4
3 4 10
3 5 18
Output
NO
Input
6
1 2 6
1 3 8
1 4 12
2 5 2
2 6 4
Output
YES
4
3 6 1
4 6 3
3 4 7
4 5 2
----------------------------------------------------------------------------------------------------
B. Count Pairs
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
----------------------------------------------------------------------------------------------------
C. Array Beauty
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 7 3 5
Output
8
Input
5 5
1 10 100 1000 10000
Output
9
----------------------------------------------------------------------------------------------------
D. Make Equal
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
228 228 228 228
Output
0
Input
3
2 2 8
Output
3
----------------------------------------------------------------------------------------------------
E. Problem from Red Panda
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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