传送门:poj1611 The Suspects
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=30010;
int par[maxn],n,m;void init(){for(int i=0;i<n;i++)par[i]=i;
}int fi(int x){if(par[x]!=x) return par[x]=fi(par[x]);return par[x];
}void join(int x,int y){int fx=fi(x),fy=fi(y);if(fx!=fy){par[fy]=fx;}
}int main(){while(~scanf("%d%d",&n,&m)){if(n==0&&m==0) break;init();int k,a,b;while(m--){scanf("%d",&k);if(k>0){scanf("%d",&a);k--;while(k--){scanf("%d",&b);join(a,b);}}}int cnt=0;for(int i=0;i<n;i++){if(fi(0)==fi(i)) cnt++;}printf("%d\n",cnt);}return 0;
}