#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n,k;
struct node{
int val;
int siz;
}fa[maxn];
int find(int x){
return x==fa[x].val?x:find(fa[x].val);
}
void merge(int x,int y){
int fx=find(x),fy=find(y);
if(fx==fy)return ;
int sizx=fa[fx].siz,sizy=fa[fy].siz;
if(fa[fx].siz<fa[fy].siz)swap(fx,fy);
fa[fy].val=fx;
fa[fx].siz=sizx+sizy;
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
fa[i].val=i;
fa[i].siz=1;
}
for(int i=1;i<=n+k-1;i++){
char op;
cin>>op;
if(op=='S'){
int a,b;cin>>a>>b;
merge(a,b);
}
else if(op=='Q'){
int a,b;cin>>a>>b;
int fx=find(a),fy=find(b);
if(fx==fy)cout<<"yes\n";
else cout<<"no\n";
}
else {
int a;
cin>>a;
int f=find(a);
cout<<fa[f].siz<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
1620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
1620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
157 ms |
1540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
157 ms |
1540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
154 ms |
1488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
154 ms |
1488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
158 ms |
1564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
158 ms |
1564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
165 ms |
1648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
165 ms |
1648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
159 ms |
1560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
159 ms |
1560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |