#include <bits/stdc++.h>
using namespace std;
#define nl '\n';
using ll = long long;
int main() {
int N, Q; cin >> N >> Q;
vector<int> C(N, 1);
vector<int> ID(N);
vector<set<int>> S(2 * N);
for(int i = 0; i < N; i++) {
ID[i] = i;
S[i] = {i};
}
int X = N;
for(int t = 0; t < (N + Q - 1); t++) {
char c; cin >> c;
if (c == 'S') {
int u, v; cin >> u >> v; --u, --v;
int U = ID[u], V = ID[v];
if (size(S[U]) < size(S[V])) swap(U, V);
for(auto &x : S[U]) {
S[X].insert(x);
C[x]++;
}
for(auto &x : S[V]) {
S[X].insert(x);
C[x]++;
}
cout << "DONE" << nl;
cout << u << " " << v << nl;
for(auto x : S[X]) cout << x << " ";
cout << nl;
ID[u] = ID[v] = X++;
}
if (c == 'Q') {
int u, d; cin >> u >> d; --u, --d;
u = ID[u]; cout << u << " " << d << nl;
cout << (S[u].count(d) ? "yes" : "no") << nl;
}
if (c == 'C') {
int x; cin >> x; --x;
cout << C[x] << nl;
}
}
}
/*
6 9
S 1 2
S 1 3
S 3 4
Q 5 1
S 4 5
S 1 6
Q 5 1
Q 1 5
C 1
C 2
C 3
C 4
C 5
C 6
4 4
S 1 2
S 1 3
S 3 4
Q 2 1
Q 2 2
Q 2 3
Q 2 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
204 ms |
2184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
204 ms |
2184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
208 ms |
2316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
208 ms |
2316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
205 ms |
2244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
205 ms |
2244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
221 ms |
2220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
221 ms |
2220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
211 ms |
2152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
211 ms |
2152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
224 ms |
2168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
224 ms |
2168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |