This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)
void solve() {
int n,q; cin>>n>>q;
vector<set<int>> a(n+1);
forn(i,n) a[i+1].insert(i+1);
vector<int> count(n+1,1);
forn(Q,n-1+q) {
char c;
cin>>c;
if (c=='S') {
int u,v; cin>>u>>v;
for (auto x:a[u]) count[x]++;
for (auto x:a[v]) count[x]++;
for (auto x:a[u]) a[v].insert(x);
for (auto x:a[v]) a[u].insert(x);
} else if (c=='Q') {
int u,x; cin>>u>>x;
cout << (a[u].count(x)?"yes\n":"no\n");
} else {
int x; cin>>x;
cout<<count[x]<<'\n';
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |