题意:n个人,有n-1个关系,表示A管理B,求管理人数为K的人数。(间接上司也算上司)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#define ll __int64
#define INF 0x3fffffff
using namespace std;
int n,k;
int dp[105];
int father[105],vis[105];
vector<vector<int> >ch(105);
void tree_dp(int root)
{
vis[root]=1;
for(int i=0;i<ch[root].size();i++){
int j=ch[root][i];
if(!vis[j]){
tree_dp(j);
dp[root]+=dp[j]+1;
}
}
}
int main()
{
//freopen("d:\\Test.txt","r",stdin);
while(cin>>n>>k){
memset(father,0,sizeof(father));
for(int i=0;i<105;i++) ch[i].clear();
for(int i=1;i<n;i++){
int f,c;
scanf("%d%d",&f,&c);
father[c]=f;
ch[f].push_back(c);
}
int root=1;
while(father[root]) root=father[root];
memset(vis,0,sizeof(vis));
memset(dp,0,sizeof(dp));
tree_dp(root);
int ans=0;
for(int i=1;i<=n;i++){
if(dp[i]==k) ans++;
}
cout<<ans<<endl;
}
return 0;
}