http://poj.org/problem?id=1611
Simple and check set, the construction number is 0 of the students are already infected, asked how many people together with him.
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cstdlib > #include <algorithm> #include <vector> #include <set> #include <map> #include <iomanip >using namespace Std;int N, m, K, T, Tt;int fa[30010];int b[510];int num[30010];int findd (int x) {if (x = = Fa[x]) return X;elsereturn findd (fa[x]);} void un (int x,int y) {int fx = FINDD (x), int fy = findd (y), if (FX = = FY) return;else{if (FY > FX) {num[fx] + = Num[fy];fa[f Y] = FX;} Else{num[fy] + = num[fx];fa[fx] = FY;}}} int main () {while (CIN >> n >> m) {if (n = = 0 && m = = 0) return 0;for (int i = 0; I <= N; i++) {Fa[i] = I;num[i] = 1;} while (m--) {cin >> k;if (k) Cin >> Tt;k--;while (K--) {cin >> T;un (T,TT);}} cout << num[0] << Endl;} return 0;}
poj-1611 and check Set