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 JavaScript (Node.js 12.16.1) (judge verdict: Wrong Answer)

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}


//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var list = new Array(N);
	var access = new Array(N).fill(false);
	var output = 0;
	for(var i = 0; i < N; i++){
		list[i] = {
			child : [],
			count : 0
		};
	}
	for(var i = 0; i < N - 1; i++){
		var tmp = nextIntArray();
		list[tmp[0] - 1].child.push(tmp[1] - 1);
		list[tmp[1] - 1].child.push(tmp[0] - 1);
	}
	var queue = [0];
	access[0] = true;
	var start = 0;
	var max = 0;
	while(queue.length > 0){
		var tmp = queue.shift();
		var child = list[tmp].child;
		for(var i = 0; i < child.length; i++){
			if(!access[child[i]]){
				access[child[i]] = true;
				list[child[i]].count = list[tmp].count + 1;
				if(max < list[child[i]].count){
					max = list[child[i]].count;
					start = child[i];
				}
				queue.push(child[i]);
			}
		}
	}
	var queue = [start];
	list[start].count = 0;
	access = new Array(N).fill(false);
	access[start] = true;
	while(queue.length > 0){
		var tmp = queue.shift();
		var child = list[tmp].child;
		for(var i = 0; i < child.length; i++){
			if(!access[child[i]]){
				access[child[i]] = true;
				list[child[i]].count = list[tmp].count + 1;
				queue.push(child[i]);
			}
		}
	}
	list.sort(function(a,b){
		return b.count - a.count;
	});
	for(var i = 0; i < N; i++){
		if(list[i].count > K){
			output++;
		}else{
			break;
		}
	}
	myout(output);
}