#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 |
1 |
Correct |
17 ms |
684 KB |
Output is correct |
2 |
Correct |
30 ms |
2380 KB |
Output is correct |
3 |
Correct |
254 ms |
48092 KB |
Output is correct |
4 |
Correct |
28 ms |
2124 KB |
Output is correct |
5 |
Correct |
28 ms |
1888 KB |
Output is correct |
6 |
Correct |
2062 ms |
377240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
684 KB |
Output is correct |
2 |
Correct |
30 ms |
2380 KB |
Output is correct |
3 |
Correct |
254 ms |
48092 KB |
Output is correct |
4 |
Correct |
28 ms |
2124 KB |
Output is correct |
5 |
Correct |
28 ms |
1888 KB |
Output is correct |
6 |
Correct |
2062 ms |
377240 KB |
Output is correct |
7 |
Correct |
18 ms |
852 KB |
Output is correct |
8 |
Correct |
28 ms |
3256 KB |
Output is correct |
9 |
Correct |
290 ms |
60936 KB |
Output is correct |
10 |
Correct |
27 ms |
2820 KB |
Output is correct |
11 |
Correct |
27 ms |
2724 KB |
Output is correct |
12 |
Correct |
2037 ms |
378032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
724 KB |
Output is correct |
2 |
Runtime error |
2589 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
724 KB |
Output is correct |
2 |
Runtime error |
2589 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
596 KB |
Output is correct |
2 |
Correct |
175 ms |
31816 KB |
Output is correct |
3 |
Correct |
176 ms |
31856 KB |
Output is correct |
4 |
Runtime error |
1301 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
596 KB |
Output is correct |
2 |
Correct |
175 ms |
31816 KB |
Output is correct |
3 |
Correct |
176 ms |
31856 KB |
Output is correct |
4 |
Runtime error |
1301 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
596 KB |
Output is correct |
2 |
Runtime error |
2693 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
596 KB |
Output is correct |
2 |
Runtime error |
2693 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
596 KB |
Output is correct |
2 |
Correct |
182 ms |
31764 KB |
Output is correct |
3 |
Correct |
184 ms |
31868 KB |
Output is correct |
4 |
Runtime error |
1377 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
596 KB |
Output is correct |
2 |
Correct |
182 ms |
31764 KB |
Output is correct |
3 |
Correct |
184 ms |
31868 KB |
Output is correct |
4 |
Runtime error |
1377 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
596 KB |
Output is correct |
2 |
Correct |
33 ms |
2208 KB |
Output is correct |
3 |
Correct |
317 ms |
47696 KB |
Output is correct |
4 |
Correct |
28 ms |
1852 KB |
Output is correct |
5 |
Correct |
28 ms |
1668 KB |
Output is correct |
6 |
Correct |
2064 ms |
376988 KB |
Output is correct |
7 |
Correct |
19 ms |
724 KB |
Output is correct |
8 |
Runtime error |
2528 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
596 KB |
Output is correct |
2 |
Correct |
33 ms |
2208 KB |
Output is correct |
3 |
Correct |
317 ms |
47696 KB |
Output is correct |
4 |
Correct |
28 ms |
1852 KB |
Output is correct |
5 |
Correct |
28 ms |
1668 KB |
Output is correct |
6 |
Correct |
2064 ms |
376988 KB |
Output is correct |
7 |
Correct |
19 ms |
724 KB |
Output is correct |
8 |
Runtime error |
2528 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |