哈哈,放假回家一周啦!这几天真是堕落得不像话(这就是为啥我会一直处在菜鸟阶段。。O.O),今天突然来了兴致开始刷题了。嗯,放着史诗BGM刷题,感觉不错不错!希望在新的一年里面能够勤奋努力学习!(感觉离我还很遥远。。)
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define MAX_N 1000005
#define INF 1000000000
typedef struct Node
{
Node* a[103];
}Node;
Node* getNode()
{
Node * p = (Node*)malloc(sizeof(Node));
for (int i = 0; i < 103; i++)
p->a[i] = NULL;
return p;
}
Node* g[105];
int n, k, x, y;
int fun(Node* cp)
{
int r = 0;
for (int i = 1; i <= n; i++)
{
if (cp->a[i] != NULL)
{
r += fun(cp->a[i]);
r += 1;
}
}
return r;
}
int main()
{
while (cin>>n>>k)
{
for (int i = 1; i <= n; i++)
g[i] = getNode();
for (int i = 1; i < n; i++)
{
cin>>x>>y;
g[x]->a[y] = g[y];
}
if (n == k)
{
cout<<1<<endl;
continue;
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
if (fun(g[i]) == k)
ans++;
}
cout<<ans<<endl;
}
}