| ||||||||||
| 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:why I am waIn Reply To:why I am wa Posted by:ecjtuxiongbp at 2005-10-29 19:11:41 #include <stdio.h>
#include <algorithm>
using namespace std;
int i,j,n,m,ans;
int const MAXN = 50000;
int uset[MAXN+1];
int Root(int v)
{
if(uset[v] == v)
return v;
uset[v] = Root(uset[v]);
return uset[v];
}
void Unite(int a,int b)
{
uset[uset[b]] = uset[a];
}
int main()
{
int a,b;
int ncase = 1;
while(scanf("%d%d",&n,&m) && n+m)
{
for(i=0; i<=n; i++)
uset[i] = i;
ans = n;
for(i=0; i<m; i++)
{
scanf("%d%d",&a,&b);
if(Root(a)!=Root(b))
{
ans--;
uset[uset[b]] = uset[a];
}
}
printf("Case %d: %d\n",ncase,ans);
ncase++;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator