| ||||||||||
| 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 | |||||||||
贴个282ms的代码,求2位数代码写法#include <stdio.h>
int student[50001],n=0;
int count;
inline int find(int x)
{
while(student[x]!=x)
{
x=student[x];
}
return x;
}
void change(int x,int y)
{
int i=0;
int px=find(x),py=find(y);
if(px!=py)
{
--count;
student[px]=py;
}
return;
}
int main(void)
{
int k=0,m=0;
int i=0,x=0,y=0;
while(scanf("%d%d",&n,&m)&&n+m)
{
for(i=1;i<=n;++i)
{
student[i]=i;
}
count=n;
for(i=0;i<m;++i)
{
scanf("%d%d",&x,&y);
change(x,y);
}
printf("Case %d: %d\n",++k,count);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator