Lakshy was walking around in the forest when he sees an odd-looking tree which he called the Orz Tree
. An Orz Tree
is a tree where each node is adjacent to at most
A tree is defined as a connected graph with
Lakshy has a rooted tree that is rooted at node Orz Tree
?
Constraints
Input Specification
The first line contains an integer
The second line contains
The next
Output Specification
Output the minimum cost (in kneecaps) for Lakshy to make his tree into an Orz Tree
.
Sample Input
6
4 10 2 1 7
1 2
2 3
1 4
2 5
2 6
Sample Output
1
Explanation for Sample Output
Lakshy's tree is depicted below (the cost to remove each node is written in red):
It can be proven that it is optimal to remove node
Comments