标签:blank style code size member ota ohs table not
Time Limit: 1000MS | Memory Limit: 20000K | |
Total Submissions: 41922 | Accepted: 20236 |
Description
Input
Output
Sample Input
100 4 2 1 2 5 10 13 11 12 14 2 0 1 2 99 2 200 2 1 5 5 1 2 3 4 5 1 0 0 0
Sample Output
4 1 1
Source
#include<iostream> #include<cstdio> using namespace std; int n,m,k; int a[30005],fa[30005]; int f(int x){ return fa[x]==x?x:fa[x]=f(fa[x]); } void unionn(int x,int y){ int fx=f(x),fy=f(y); if(fx!=fy)fa[fx]=fy; } int main(){ while(scanf("%d%d",&n,&m)!=EOF){ if(!m&&!n)break; int cnt=1; for(int i=0;i<n;i++)fa[i]=i; for(int i=1;i<=m;i++){ scanf("%d",&k);scanf("%d",&a[0]); for(int j=1;j<k;j++){ scanf("%d",&a[j]); unionn(a[j],a[j-1]); } } int gg=f(0); for(int i=1;i<n;i++){ if(gg==f(i))cnt++; } printf("%d\n",cnt); } return 0; }
标签:blank style code size member ota ohs table not
原文地址:http://www.cnblogs.com/zzyh/p/7423778.html