| ||||||||||
| 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 | |||||||||
牛人给看下哈……先谢了……(runtime error)#include<stdio.h>
int d[30005],f[30005],s[30005],n;
void merge(int a,int b)
{
int x1=a,x2=a,y=b;
//分别记录 f(father) s(son)
while (y!=f[y]) y=f[y];
while (x1!=f[x1]) { x1=f[x1]; d[x1]+=(d[y]+1); }
while (x2!=s[x2]) { x2=s[x2]; d[x2]+=(d[y]+1); }
d[a]+=(d[y]+1);
s[x2]=y;
f[y]=x2;
}
int main()
{
int i,a,b;
char ch;
freopen("aoe.in","r",stdin);
freopen("aoe.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++)
{
f[i]=i;
s[i]=i;
d[i]=0;
}
for (i=0;i<n;i++)
{
scanf("%c",&ch);
scanf("%c",&ch);
if (ch=='M')
{
scanf("%d %d",&a,&b);
merge(a,b);
}
if (ch=='C')
{
scanf("%d",&a);
printf("%d\n",d[a]);
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator