Code:
// luogu-judger-enable-o2
#include <queue>
#include <cstdio>
#include <algorithm>
#define N 1000005
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
queue<int>q;
int n,edges;
int deg[N],hd[N],to[N<<1],nex[N<<1],num[N],dep[N],vis[N];
void add(int u,int v)
{
nex[++edges]=hd[u],hd[u]=edges,to[edges]=v;
}
int main()
{
int i,j,L;
// setIO("input");
scanf("%d%d",&n,&L);
for(i=1;i<n;++i)
{
int a,b;
scanf("%d%d",&a,&b),add(a,b),add(b,a),++deg[a],++deg[b];
}
for(i=1;i<=n;++i) if(deg[i]==1) q.push(i),vis[i]=1;
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=hd[u];i;i=nex[i])
{
if(!vis[to[i]])
{
--deg[to[i]];
if(deg[to[i]]<=1)
vis[to[i]]=1,dep[to[i]]=dep[u]+1,q.push(to[i]);
}
}
}
for(i=1;i<=n;++i) ++num[dep[i]];
int ans=0;
for(i=0;i<=n;++i)
ans+=min(2*L,num[i]);
printf("%d\n",ans);
return 0;
}