标签:
题目连接:戳ME
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int M = 1e2+5; int n, k; int par[M]; int sum[M]; void find(int x) { if( par[x]!=x ) { sum[par[x]]++; find(par[x]); } else return; } int main() { while( ~scanf("%d %d", &n, &k ) ) { memset( par, 0, sizeof(par) ); memset( sum, 0, sizeof(sum) ); for( int i=1; i<=n; i++ ) par[i] = i; for( int i=1; i<n; i++ ) { int x, y; scanf("%d %d", &x, &y ); par[y] = x; } for( int i=1; i<=n; i++ ) find( i ); int ret = 0; for( int i=1; i<=n; i++ ) { if( sum[i]==k ) ret++; } printf("%d\n", ret ); } }
HDU OJ 5326 Work( 2015多校联合训练第3场) 并查集
标签:
原文地址:http://www.cnblogs.com/TaoTaoCome/p/4685453.html