Removing trees

0

0 votes
Basics of Greedy Algorithms, Algorithms, Algorithms, Greedy algorithm, Greedy Algorithms, Root, Hard, Approved, Tree, Open
Problem

You are given a tree consisting of N vertices. What is the minimum number of vertices that should be removed such that all the remaining parts of the initial tree contain less than K vertices?

Input format

  • The first line contains one integer K.
  • The second line contains one integer N.
  • The third line contains N1 space-separated integers ai for 2iN which means that vertices i and ai are connected by an edge.

Output format

Print one number denoting the answer to the question.

Constraints

1K, N10000ai<i

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We can remove vertices 2, 3, 6.

Editor Image

?