| ||||||||||
| 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 | |||||||||
怎么就过不了呢??? 1988#include <iostream>
#include<string.h>
#include <stdio.h>
using namespace std;
int p[30010];
int up[30010];
int sum[30010];
int find (int x)
{ if(p[x] == x)
{return x;}
else
{p[x]=find(p[x]);
return p[x] ;
}
}
void unsin_123(int x ,int y)
{ int px,py;
px=find(x);
py=find(y);
if(px!=py)
{
up[py]+=sum[px];
sum[px]+=sum[py];
p[py]=px;
}
}
int main()
{ int n;
char str;
int j,k;
memset(up,0,sizeof(up));
//cin>>n;
scanf("%d",&n);
for(int i=1;i<=n;i++ )
p[i]=i;
for(int i=1;i<=n;i++)
sum[i]=1;
while (n>0)
{ cin>>str;
if(str=='M')
{//cin>>j>>k;
scanf("%d%d",&j,&k);
unsin_123(j,k);
}
else if(str=='C')
{//cin>>j;
scanf("%d",&j);
//cout<<sum[p[j]]-1-up[j]<<endl;
printf("%d",sum[p[j]]-1-up[j]);
}
n--;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator