#include <iostream>
using namespace std;
int fa[30000], put[30000];
void init(int n)
{
for(int i = 0; i < n; ++i)
{
fa[i] = i;
}
}
int find(int u)
{
if(fa[u] != u)
{
fa[u] = find(fa[u]);
}
return fa[u];
}
void unin(int u, int v)
{
int fau = find(u);
int fav = find(v);
if(fau == fav) return ;
fa[fav] = fau;
}
int main ()
{
int n, m;
while(cin >> n >> m && n >=0 && m >= 0 && n <= 30000 && m <= 500 && (n || m))
{
init(n);
int k;
while(m--)
{
cin >> k;
for(int i = 0; i < k; ++i)
{
cin >> put[i];
unin(put[0], put[i]);
///一行有多个样例,转化为K - 1组
}
}
int f0 = find(0);
int cut = 0;
for(int i = 0; i < n; ++i)
{
if(f0 == find(i))
cut++;
}
cout << cut << endl;
}
return 0;
}
POJ1611----HLG1160
最新推荐文章于 2014-08-11 21:04:00 发布