Submission #1096319

#TimeUsernameProblemLanguageResultExecution timeMemory
1096319vjudge1Inside information (BOI21_servers)C++14
0 / 100
165 ms1648 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...