标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326
1 #include<stdio.h> 2 #include<cstring> 3 const int MAX = 105; 4 int n, k; 5 int a[MAX][MAX]; 6 int b[MAX]; 7 void dfs(int i, int j){ 8 for(int p = 0; p < n; ++p){ 9 if( a[j][p] ){ 10 b[i]++; 11 dfs(i,p); 12 } 13 } 14 } 15 int main(){ 16 freopen("1011.in", "r", stdin); 17 freopen("a.out","w",stdout); 18 int i, j; 19 int A, B; 20 int ans; 21 while(scanf("%d%d",&n,&k)==2){ 22 ans = 0; 23 memset(a,0,sizeof(a)); 24 memset(b,0,sizeof(b)); 25 for( i = 1; i <= n-1; ++i){ 26 scanf("%d%d",&A,&B); 27 a[A-1][B-1] = 1; 28 } 29 for( i = 0; i < n; ++i){ 30 for( j = 0; j < n; ++j){ 31 if( a[i][j] ){ 32 b[i]++; 33 dfs(i,j); 34 } 35 } 36 } 37 for( i = 0; i < n; ++i){ 38 // printf("%d\n",b[i]); 39 if( b[i] == k ) 40 ans++; 41 } 42 printf("%d\n",ans); 43 } 44 }
标签:
原文地址:http://www.cnblogs.com/blueprintf/p/4703556.html