#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
ll read() {
ll s=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*f;
}
#define maxn 30005
int fa[maxn],dis[maxn],length[maxn];
int find(int x) {
if(fa[x]==x) return x;
int nx=find(fa[x]);
dis[x]+=dis[fa[x]];
return fa[x]=nx;
}
void move(int x,int y) {
int xx=find(x),yy=find(y);
fa[xx]=yy;
dis[xx]+=length[yy];
length[yy]+=length[xx];
}
void check(int x) {
int xx=find(x);
printf("%d\n",dis[x]);
}
int n;
int main() {
for(int i=1;i<=maxn;i++) fa[i]=i;
for(int i=1;i<=maxn;i++) length[i]=1;
n=read();
while(n--) {
char opt;scanf("%1s",&opt);
int x=read();
if(opt=='M') {
int y=read();
move(x,y);
}else if(opt=='C') {
check(x);
}
}
return 0;
}
这个n在这里输入就没有问题,而
int n;
int main() {
n=read();
for(int i=1;i<=maxn;i++) fa[i]=i;
for(int i=1;i<=maxn;i++) length[i]=1;
//上方的n在这里读入
while(n--) {
char opt;scanf("%1s",&opt);
int x=read();
if(opt=='M') {
int y=read();
move(x,y);
}else if(opt=='C') {
check(x);
}
}
return 0;
}
n在这个位置读入就会出锅呢