mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
27767e72ab
2800-2899
59 lines
1.1 KiB
C++
59 lines
1.1 KiB
C++
#include<iostream>
|
|
#include<cstdio>
|
|
#include<algorithm>
|
|
#include<cmath>
|
|
#include<string>
|
|
#include<memory.h>
|
|
#include<cstring>
|
|
using namespace std;
|
|
int father[30002],low[30002],high[30002];
|
|
int find(int x)
|
|
{
|
|
if(x==father[x])
|
|
return x;
|
|
int dx=find(father[x]);
|
|
low[x]+=low[father[x]];
|
|
return father[x]=dx;
|
|
}
|
|
void clear()
|
|
{
|
|
for(int i=0;i<30002;i++)
|
|
{
|
|
father[i]=i;
|
|
high[i]=1;
|
|
}
|
|
memset(low,0,sizeof(low));
|
|
}
|
|
int main()
|
|
{
|
|
char ch;
|
|
int a,b,n;
|
|
while(cin>>n)
|
|
{
|
|
getchar();
|
|
clear();
|
|
while(n--)
|
|
{
|
|
cin>>ch;
|
|
if(ch=='M')
|
|
{
|
|
scanf("%d %d%*c",&a,&b);
|
|
int x=find(a);
|
|
int y=find(b);
|
|
if(x==y)
|
|
continue;
|
|
father[x]=y;
|
|
low[x]=high[y];
|
|
high[y]+=high[x];
|
|
}
|
|
if(ch=='C')
|
|
{
|
|
scanf("%d%*c",&a);
|
|
find(a);
|
|
cout<<low[a]<<endl;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|