才学个树和图论就遇“春花怒放”QAQ
#include<bits/stdc++.h>
using namespace std;
struct no{
int x,r;
}e;
vector <int> tree[100011];
queue <no> s;
bool q[100011];
int n,d,a,b,ans,i;
int main()
{
scanf("%d %d", &n, &d);
for(i = 1;i < n;i ++)
{
scanf("%d %d",&a,&b);
tree[a].push_back(b);
tree[b].push_back(a);
}
e.x = 1;
s.push(e);
while(!s.empty()){
no v = s.front();
s.pop();
if(v.r>=d)break;
e.r = v.r + 1;
for(i = 0;i < tree[v.x].size();i ++)
{
if(q[tree[v.x][i]])continue;
q[tree[v.x][i]] = 1;
e.x = tree[v.x][i];
s.push(e);
ans++;
}
}
printf("%d\n",ans);
return 0;
}