| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么是RE?#include<iostream>
using namespace std;
int Find(int x,int S[])
{
if(S[x] < 0)
return x;
else
return S[x] = Find(S[x],S);
}
void SetUnion(int S[],int root1,int root2)
{
int max,min;
root1 = Find(root1,S);
root2 = Find(root2,S);
max = root1 > root2 ? root1 : root2;
min = root1 > root2 ? root2 : root1;
S[max] = min;
}
void MakeSet(int S[],int n)
{
int i;
for(i = 0; i < n; i++)
S[i] = -1;
}
int set[30001];
int main()
{
int m,n;
int k,i,j,mm,nn;
int total;
while(cin>>m>>n)
{
total = 0;
if((0 == m) && (0 == n))
break;
MakeSet(set,m);
for(i = 0; i < n; i++)
{
cin>>k;
for(j = 0; j < k; j++)
{
cin>>mm;
if(j)
SetUnion(set,nn,mm);
nn = mm;
}
}
for(i = 0; i < m; i++)
{
Find(i,set);
}
for(i = 0; i < m; i++)
{
if(Find(0,set) == Find(i,set))
total++;
}
cout<<total<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator