Problem:
Score : 600 points

Problem Statement

Given an undirected tree, let the distance between vertices u and v be the
number of edges on the simple path from u to v.
The diameter of a tree is the maximum among the distances between any two vertices.
We will call a tree good if and only if its diameter is at most K.

You are given an undirected tree with N vertices numbered 1 through N.
For each i (1≦i≦N-1), there is an edge connecting vertices A_i and B_i.

You want to remove zero or more vertices from the tree, so that the resulting tree is good.
When a vertex is removed, all incident edges will also be removed.
The resulting graph must be connected.

Find the minimum number of vertices that you need to remove in order to produce a good tree.

Constraints

2≦N≦2000

1≦K≦N-1

1≦A_i≦N, 1≦B_i≦N

The graph defined by A_i and B_i is a tree.

Input

The input is given from Standard Input in the following format:

N K
A_1 B_1
A_2 B_2
:
A_{N-1} B_{N-1}

Output

Print the minimum number of vertices that you need to remove in order to produce a good tree.

Sample Input 1

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

Sample Output 1

2

The tree is shown below. Removing vertices 5 and 6 will result in a good tree with the diameter of 2.

Sample Input 2

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

Sample Output 2

0

Since the given tree is already good, you do not need to remove any vertex.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cstdio>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POSSIBLE(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Possible(i) cout<<(i?"Possible":"Impossible")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
//
int N,K;
vector<int> V[2000];
int num[2000];
int m;
void DFS(int n,int ran){
	FOR(i,0,V[n].size()){
		if(num[V[n][i]]==INF){
			num[V[n][i]]=ran;
			if(K/2==ran){
				if(K%2){
					m=max(m,(int)V[V[n][i]].size()-1);
				}
				continue;
			}else{
				DFS(V[n][i],ran+1);
			}
		}
	}
}
void DFS_s(int n,int ran){
	FOR(i,0,V[n].size()){
		if(num[V[n][i]]==INF){
			num[V[n][i]]=ran;
			if(K==ran){
				continue;
			}else{
				DFS(V[n][i],ran+1);
			}
		}
	}
}
int main(){
	cin>>N>>K;
	FOR(i,0,N-1){
		int A,B;
		cin>>A>>B;
		A--;B--;
		V[A].PB(B);
		V[B].PB(A);
	}
	int ans=INF;
	FOR(i,0,N){
		fill(num,num+N,INF);
		num[i]=0;
		m=0;
		if(V[i].size()==1){
			DFS_s(i,1);
			sort(num,num+N);
			ans=min(ans,N-(int)(upper_bound(num,num+N,K)-num));
		}
		DFS(i,1);
		sort(num,num+N);
		if(K%2==0){
			ans=min(ans,N-(int)(upper_bound(num,num+N,K/2)-num));
		}else{
			ans=min(ans,N-(int)(upper_bound(num,num+N,K/2)-num)-m);
		}
	}
	cout<<ans<<endl;
	return 0;
}