F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Tree Cutting

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 697    Accepted Submission(s): 182


Problem Description
Given a tree (connected undirected graph with $n$ vertexes and $n - 1$ edges), you are required to delete as few vertexes as possible such that the remaining graph is still a tree and its diameter shall not exceed $k$. The diameter of a tree is the length of its longest path.
 

Input
The first line contains one positive integer $T$ ($1\le T \le 15$), denoting the number of test cases. For each test case:

The first line of the input contains two integers $n, k\,(1\le n,k \le 300000)$.

Each of the following $n - 1$ lines contains two integers $u, v\, (1\le u,v \le n, u\neq v)$, indicating that there is an edge connecting vertex $u$ and $v$ in the tree.
 

Output
For each test case:

You should just output one integer indicating the number of vertexes to be deleted.
 

Sample Input
1 10 3 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10
 

Sample Output
4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 05:31:14, Gzip enabled