#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
struct query {
int t, u, v, i;
};
const int MN = 120005;
int n, q, u, v, par[MN], sz[MN];
bitset<MN> b[MN];
query qs[MN * 2];
char c;
vector<int> a[MN];
int find(int x) {
return x == par[x] ? x : par[x] = find(par[x]);
}
bool merge(int x, int y) {
x = find(x), y = find(y);
if (x == y) return false;
par[x] = par[y];
sz[y] += sz[x];
return true;
}
int32_t main() {
boost();
cin >> n >> q;
for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1, b[i][i] = 1;
for (int i = 1; i < n + q; i++) {
cin >> c >> u;
if (c != 'C') cin >> v;
if (c == 'S') {
a[u].push_back(v);
a[v].push_back(u);
qs[i] = {0, u, v, i};
merge(u, v);
b[u] |= b[v];
b[v] |= b[u];
} else if (c == 'Q') {
qs[i] = {1, u, v, i};
if (b[u][v]) printf("yes\n");
else printf("no\n");
} else {
qs[i] = {2, u, 0, i};
printf("%lld\n", sz[find(u)]);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8776 KB |
Output is correct |
2 |
Correct |
79 ms |
67680 KB |
Output is correct |
3 |
Correct |
64 ms |
67768 KB |
Output is correct |
4 |
Correct |
77 ms |
67712 KB |
Output is correct |
5 |
Correct |
80 ms |
67704 KB |
Output is correct |
6 |
Correct |
73 ms |
67784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8776 KB |
Output is correct |
2 |
Correct |
79 ms |
67680 KB |
Output is correct |
3 |
Correct |
64 ms |
67768 KB |
Output is correct |
4 |
Correct |
77 ms |
67712 KB |
Output is correct |
5 |
Correct |
80 ms |
67704 KB |
Output is correct |
6 |
Correct |
73 ms |
67784 KB |
Output is correct |
7 |
Incorrect |
22 ms |
8864 KB |
Extra information in the output file |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8792 KB |
Output is correct |
2 |
Runtime error |
198 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8792 KB |
Output is correct |
2 |
Runtime error |
198 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
8812 KB |
Output is correct |
2 |
Runtime error |
211 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
8812 KB |
Output is correct |
2 |
Runtime error |
211 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
8780 KB |
Output is correct |
2 |
Runtime error |
208 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
8780 KB |
Output is correct |
2 |
Runtime error |
208 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8772 KB |
Output is correct |
2 |
Runtime error |
217 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8772 KB |
Output is correct |
2 |
Runtime error |
217 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8908 KB |
Output is correct |
2 |
Correct |
89 ms |
67620 KB |
Output is correct |
3 |
Correct |
80 ms |
67684 KB |
Output is correct |
4 |
Correct |
90 ms |
67784 KB |
Output is correct |
5 |
Correct |
74 ms |
67716 KB |
Output is correct |
6 |
Correct |
76 ms |
67752 KB |
Output is correct |
7 |
Correct |
25 ms |
8896 KB |
Output is correct |
8 |
Runtime error |
214 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8908 KB |
Output is correct |
2 |
Correct |
89 ms |
67620 KB |
Output is correct |
3 |
Correct |
80 ms |
67684 KB |
Output is correct |
4 |
Correct |
90 ms |
67784 KB |
Output is correct |
5 |
Correct |
74 ms |
67716 KB |
Output is correct |
6 |
Correct |
76 ms |
67752 KB |
Output is correct |
7 |
Correct |
25 ms |
8896 KB |
Output is correct |
8 |
Runtime error |
214 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |