Mock CCC '19 Contest 1 S3 - Saitama's Trees

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
ONE PUNCHHHHHHHHH (Saitama)

Saitama, for Christmas, wants an undirected tree. Each edge in the node has been given a weight of 1, and therefore, means that the distance between node a and b is the number of edges on an acyclic path from a to b.

Unfortunately, Saitama will only like his present if it's diameter is at most D. The diameter of a tree is the maximum distance between any two vertices.

The undirected tree Saitama received has N vertices, labelled 1 through N. You want to remove an amount of vertices (or, you don't have to remove any if Saitama likes his present), such that the resulting tree is one Saitama likes. If you remove a node, all edges that are connecting to it will disappear as well.

As you are lazy, you want to find out the minimum number of vertices to remove in order to make Saitama happy, else you get One Punched!

Constraints

  • 2 \le N \le 2000
  • 1 \le D \le N-1
  • 1 \le A_i , B_i \le N, such that A_i and B_i are nodes that are connected.
  • The graph G will be a tree.

Input Specification

The first line of input will contain 2 space separated integers, N and D.

The next N-1 lines will contain two space separated integers, A_i and B_i, denoting a connection between A_i and B_i that is bidirectional.

Output Specification

You are to output a single integer, the minimum number of nodes that you have to remove to make Saitama happy.

Sample Input 1

6 2
1 2
3 2
4 2
1 6
5 6

Sample Output 1

2

Comments

There are no comments at the moment.