Varun_Shah's blog

By Varun_Shah, history, 7 years ago, In English

Given a tree with N nodes we are required to seperate a connected component with exactly k nodes. You are given queries specifying this k. We need to find the minimum edges to be removed for each query.
First line specifies N.
Next N-1 lines specify edges.
Next line shows Q(number of queries).
Subsequent Q lines contain k for each query.

Constraint:
N <= 3000
Q <= 3000
K <= N

Example:
Input:
5
1 2
1 3
1 4
1 5
3
1
2
4

Output:
1
3
1

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Varun_Shah (previous revision, new revision, compare).

»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think this is famous problem — Barricades from Poland. You can read it in book 'Looking for Challenges.