Tree tearing
Practice
3.9 (54 votes)
Approved
Greedy algorithms
Medium
Open
Trees
Problem
92% Success 1145 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a tree consising of N vertices. What is the minimum number of vertices that should be removed that all the remaining parts of the initial tree will contain less than K vertices?
Input
The first line contains one integer K.
The second line contains one integer N.
The third line contains N-1 space-separated intgers ai for 2 <= i <= N which means that vertices i and ai are connected by an edge.
Output
Output one number - answer for the question.
Constraints
- 1 <= K, N <= 10 000
- ai < i
Submissions
Please login to view your submissions
Similar Problems
Points:50
2 votes
Tags:
Greedy AlgorithmsMathAlgorithmsBasics of Greedy Algorithms
Points:30
58 votes
Tags:
AlgorithmsEasyMonthly-ContestReady
Points:50
6 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Editorial