| ||||||||||
| 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 | |||||||||
有木有大神帮忙看看,死活wa;
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=30000+10;
struct node
{
int h,low;
} a[N];
int f[N],m;
int find(int x)
{
if(f[x]==-1)
return x;
a[x].low+=a[f[x]].low;
return f[x]=find(f[x]);
}
int main()
{
scanf("%d",&m);
char c;
int x,y;
memset(f,-1,sizeof(f));
for(int i=1; i<=N; i++)
a[i].h=1,a[i].low=0;
while(m--)
{
getchar();
scanf("%c",&c);
if(c=='C')
{
scanf("%d",&x);
find(x);
printf("%d\n",a[x].low);
}
else
{
scanf("%d%d",&x,&y);
int xx=find(x);
int yy=find(y);
if(xx==yy)
continue;
f[xx]=yy;
a[xx].low=a[yy].h;
a[yy].h+=a[xx].h;
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator