标签:水
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326
7 2 1 2 1 3 2 4 2 5 3 6 3 7
2
#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1000000007; int s[105][105],f[105]; int n,k; int cnt,ans; void solve(int m) { int t = m; if (t>=n||f[t]==0) return ; for (int i=1; i<=n; i++) { if (s[t][i]) { cnt+=f[i]; solve(i); } } } int main() { int a,b; while (scanf ("%d%d",&n,&k)==2) { memset(s, 0, sizeof(s)); memset(f, 0, sizeof(f)); for (int j=1; j<n; j++) { scanf ("%d%d",&a,&b); s[a][b] = 1; f[a]++; } cnt=0,ans=0; for (int i=1; i<=n; i++) { cnt = f[i]; solve(i); if (cnt == k) ans++; } printf ("%d\n",ans); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:水
原文地址:http://blog.csdn.net/d_x_d/article/details/48024159