#include<bits/stdc++.h>
using namespace std;
const int N = 4005;;
int cnt[N];
vector<int> v[N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
v[i].push_back(i);
cnt[i] = 1;
}
auto merge = [&](vector<int> &a, vector<int>& b) {
vector<int> c;
for (int i = 0; i < (int) a.size(); ++i) {
c.push_back(a[i]);
cnt[a[i]]++;
}
for (int i = 0; i < (int) b.size(); ++i) {
c.push_back(b[i]);
cnt[b[i]]++;
}
a = b = c;
};
for (int i = 0; i < n + k - 1; ++i) {
char c;
cin >> c;
if (c == 'S') {
int a, b;
cin >> a >> b;
merge(v[a], v[b]);
}
else if (c == 'C') {
int a;
cin >> a;
cout << cnt[a] << '\n';
}
else if (c == 'Q') {
int a, b;
cin >> a >> b;
bool ans = false;
for (int j = 0; j < (int) v[a].size(); ++j) {
if (v[a][j] == b) {
ans = true;
break;
}
}
cout << (ans ? "yes" : "no") << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1092 KB |
Output is correct |
2 |
Correct |
31 ms |
1484 KB |
Output is correct |
3 |
Correct |
64 ms |
5580 KB |
Output is correct |
4 |
Correct |
36 ms |
1388 KB |
Output is correct |
5 |
Correct |
34 ms |
1388 KB |
Output is correct |
6 |
Correct |
199 ms |
41216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1092 KB |
Output is correct |
2 |
Correct |
31 ms |
1484 KB |
Output is correct |
3 |
Correct |
64 ms |
5580 KB |
Output is correct |
4 |
Correct |
36 ms |
1388 KB |
Output is correct |
5 |
Correct |
34 ms |
1388 KB |
Output is correct |
6 |
Correct |
199 ms |
41216 KB |
Output is correct |
7 |
Correct |
24 ms |
1200 KB |
Output is correct |
8 |
Correct |
28 ms |
1460 KB |
Output is correct |
9 |
Correct |
53 ms |
6716 KB |
Output is correct |
10 |
Correct |
30 ms |
1356 KB |
Output is correct |
11 |
Correct |
36 ms |
1280 KB |
Output is correct |
12 |
Correct |
156 ms |
41148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1100 KB |
Output is correct |
2 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1100 KB |
Output is correct |
2 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1076 KB |
Output is correct |
2 |
Runtime error |
1 ms |
944 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1076 KB |
Output is correct |
2 |
Runtime error |
1 ms |
944 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1112 KB |
Output is correct |
2 |
Runtime error |
2 ms |
940 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1112 KB |
Output is correct |
2 |
Runtime error |
2 ms |
940 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1136 KB |
Output is correct |
2 |
Runtime error |
2 ms |
916 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1136 KB |
Output is correct |
2 |
Runtime error |
2 ms |
916 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1108 KB |
Output is correct |
2 |
Correct |
46 ms |
1436 KB |
Output is correct |
3 |
Correct |
60 ms |
5556 KB |
Output is correct |
4 |
Correct |
36 ms |
1436 KB |
Output is correct |
5 |
Correct |
31 ms |
1344 KB |
Output is correct |
6 |
Correct |
208 ms |
41224 KB |
Output is correct |
7 |
Correct |
27 ms |
1296 KB |
Output is correct |
8 |
Runtime error |
2 ms |
980 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1108 KB |
Output is correct |
2 |
Correct |
46 ms |
1436 KB |
Output is correct |
3 |
Correct |
60 ms |
5556 KB |
Output is correct |
4 |
Correct |
36 ms |
1436 KB |
Output is correct |
5 |
Correct |
31 ms |
1344 KB |
Output is correct |
6 |
Correct |
208 ms |
41224 KB |
Output is correct |
7 |
Correct |
27 ms |
1296 KB |
Output is correct |
8 |
Runtime error |
2 ms |
980 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |