标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 230 Accepted Submission(s): 171
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 6 int n,k,s; 7 int a[105][105]; 8 9 int dfs(int g) 10 { 11 for(int i=1;i<=n;i++) 12 { 13 if(a[g][i]==1) 14 { 15 s++; 16 dfs(i); 17 } 18 } 19 return 0; 20 } 21 22 int main() 23 { 24 int i,j,x,y; 25 while(scanf("%d %d",&n,&k)!=EOF) 26 { 27 memset(a,0,sizeof(a)); 28 for(i=1;i<=n-1;i++) 29 { 30 scanf("%d %d",&x,&y); 31 a[x][y]=1; 32 } 33 int ans=0; 34 for(i=1;i<=n;i++) 35 { 36 s=0; 37 dfs(i); 38 if(s==k) 39 ans++; 40 } 41 printf("%d\n",ans); 42 } 43 }
标签:
原文地址:http://www.cnblogs.com/cyd308/p/4684258.html