#include <bits/stdc++.h>
using namespace std;
int f[30005],d[30005],l[30005];
int find(int x)
{
if(f[x]==x) return x;
f[x]=find(f[x]);
d[x]+=d[f[x]];
return f[x];
}
int main()
{
for(int i=1;i<=30002;i++) f[i]=i,l[i]=1;
int p;cin>>p;
while(p--)
{
char op;cin>>op;
if(op=='M')
{
int x,y;cin>>x>>y;
int fx=find(x),fy=find(y);
f[fx]=fy;
d[fx]+=l[fy];
l[fy]+=l[fx];
}
else
{
int x;cin>>x;
cout<<d[x]<<'\n';
}
}
return 0;
}
代码见上,思路和tj①差不多。但是18pts