标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 583 Accepted Submission(s):
392
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int n,m,Map[110][110]; 8 9 int dfs(int x) 10 { 11 int sum=0; 12 for (int i=1;i<=n;i++) 13 { 14 if (Map[x][i]==1) 15 { 16 sum++; 17 sum+=dfs(i); 18 } 19 } 20 return sum; 21 } 22 23 int main() 24 { 25 int a,b,ans; 26 while (~scanf("%d%d",&n,&m)) 27 { 28 ans=0; 29 memset(Map,0,sizeof(Map)); 30 //memset(ok,0,sizeof(ok)); 31 for (int i=1; i<=n-1; i++) 32 { 33 scanf("%d%d",&a,&b); 34 Map[a][b]=1; 35 } 36 for (int i=1;i<=n;i++) 37 { 38 if (dfs(i)==m) 39 ans++; 40 } 41 printf ("%d\n",ans); 42 } 43 return 0; 44 }
标签:
原文地址:http://www.cnblogs.com/qq-star/p/4686536.html