链接:https://codeforces.ml/contest/1337/problem/C

Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.

df63f4ac458c231c1258e895434dcb4c2f090f09.pnguploading.4e448015.gif正在上传…重新上传取消

 

There are nn cities and n−1n−1 two-way roads connecting pairs of cities in the kingdom. From any city, you can reach any other city by walking through some roads. The cities are numbered from 11 to nn, and the city 11 is the capital of the kingdom. So, the kingdom has a tree structure.

As the queen, Linova plans to choose exactly kk cities developing industry, while the other cities will develop tourism. The capital also can be either industrial or tourism city.

A meeting is held in the capital once a year. To attend the meeting, each industry city sends an envoy. All envoys will follow the shortest path from the departure city to the capital (which is unique).

Traveling in tourism cities is pleasant. For each envoy, his happiness is equal to the number of tourism cities on his path.

In order to be a queen loved by people, Linova wants to choose kk cities which can maximize the sum of happinesses of all envoys. Can you calculate the maximum sum for her?

Input

The first line contains two integers nn and kk (2≤n≤2⋅1052≤n≤2⋅105, 1≤k<n1≤k<n)  — the number of cities and industry cities respectively.

Each of the next n−1n−1 lines contains two integers uu and vv (1≤u,v≤n1≤u,v≤n), denoting there is a road connecting city uu and city vv.

It is guaranteed that from any city, you can reach any other city by the roads.

Output

Print the only line containing a single integer  — the maximum possible sum of happinesses of all envoys.

Examples

input

Copy

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

output

Copy

7

input

Copy

4 1
1 2
1 3
2 4

output

Copy

2

input

Copy

8 5
7 5
1 7
6 1
3 7
8 3
2 1
4 5

output

Copy

9

Note

In the first example, Linova can choose cities 22, 55, 66, 77 to develop industry, then the happiness of the envoy from city 22 is 11, the happiness of envoys from cities 55, 66, 77 is 22. The sum of happinesses is 77, and it can be proved to be the maximum one.

3ffb39c877eca7565234f5b27836c176c6a85f3f.pnguploading.4e448015.gif正在上传…重新上传取消

In the second example, choosing cities 33, 44 developing industry can reach a sum of 33, but remember that Linova plans to choose exactly kk cities developing industry, then the maximum sum is 22.

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,k,l,r,t,s,a[200001];
long long vis[200001],f[200001];
map<long long,long long>m[200001],p;
struct node{
	long long sum;
	long long id;
}x[200001];
void dfs(int i,int tip)
{
	for(int j=1;j<=p[i];j++)
	{
		if(f[m[i][j]]==0)
		{
			f[m[i][j]]=1;
			dfs(m[i][j],tip+1);
			x[m[i][j]].sum=tip+1;
			a[i]+=a[m[i][j]];
		}
	}
	a[i]++;
} 
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n-1;i++)
	{
		cin>>l>>r;
		p[l]++;
		p[r]++;
		m[l][p[l]]=r;
		m[r][p[r]]=l;
	}
	f[1]=1;
	dfs(1,0);
	f[1]=0;
	x[1].sum=0;
	for(int i=1;i<=n;i++)
	{
		x[i].id=i;
		vis[i]=x[i].sum;
	}
	s=0;
	for(int i=1;i<=n;i++)
	{
		vis[i]+=1-a[i];
		//cout<<vis[i]<<" ";
	}
	sort(vis+1,vis+1+n);
	for(int i=n;i>=n-k+1;i--)
	{
		s+=vis[i];
	}
	cout<<s<<endl;
}