#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4001;
bitset <MAXN> dd[MAXN];
bitset <MAXN> pp[MAXN];
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
dd[i][i] = 1; pp[i][i] = 1;
}
for (int i = 1; i <= n + k - 1; i++) {
char c;
cin >> c;
if (c == 'S') {
int a, b;
cin >> a >> b;
dd[a] |= dd[b]; dd[b] = dd[a];
for (int j = 1; j <= n; j++) {
if (dd[a][j]) pp[j][a] = 1;
if (dd[b][j]) pp[j][b] = 1;
}
} else if (c == 'Q') {
int x, y;
cin >> x >> y;
cout << (dd[x][y] ? "yes\n" : "no\n");
} else {
int x;
cin >> x;
cout << pp[x].count() << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Correct |
36 ms |
4596 KB |
Output is correct |
3 |
Correct |
42 ms |
4688 KB |
Output is correct |
4 |
Correct |
37 ms |
4564 KB |
Output is correct |
5 |
Correct |
33 ms |
4688 KB |
Output is correct |
6 |
Correct |
50 ms |
4720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Correct |
36 ms |
4596 KB |
Output is correct |
3 |
Correct |
42 ms |
4688 KB |
Output is correct |
4 |
Correct |
37 ms |
4564 KB |
Output is correct |
5 |
Correct |
33 ms |
4688 KB |
Output is correct |
6 |
Correct |
50 ms |
4720 KB |
Output is correct |
7 |
Correct |
15 ms |
2652 KB |
Output is correct |
8 |
Correct |
42 ms |
4484 KB |
Output is correct |
9 |
Correct |
50 ms |
4696 KB |
Output is correct |
10 |
Correct |
55 ms |
4544 KB |
Output is correct |
11 |
Correct |
41 ms |
4436 KB |
Output is correct |
12 |
Correct |
55 ms |
4756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2788 KB |
Output is correct |
2 |
Runtime error |
4 ms |
8540 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2788 KB |
Output is correct |
2 |
Runtime error |
4 ms |
8540 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Runtime error |
4 ms |
8540 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Runtime error |
4 ms |
8540 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Runtime error |
4 ms |
8536 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Runtime error |
4 ms |
8536 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2896 KB |
Output is correct |
2 |
Runtime error |
6 ms |
8472 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2896 KB |
Output is correct |
2 |
Runtime error |
6 ms |
8472 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Correct |
33 ms |
4664 KB |
Output is correct |
3 |
Correct |
52 ms |
4720 KB |
Output is correct |
4 |
Correct |
38 ms |
4688 KB |
Output is correct |
5 |
Correct |
34 ms |
4600 KB |
Output is correct |
6 |
Correct |
48 ms |
4692 KB |
Output is correct |
7 |
Correct |
14 ms |
2908 KB |
Output is correct |
8 |
Runtime error |
4 ms |
8540 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Correct |
33 ms |
4664 KB |
Output is correct |
3 |
Correct |
52 ms |
4720 KB |
Output is correct |
4 |
Correct |
38 ms |
4688 KB |
Output is correct |
5 |
Correct |
34 ms |
4600 KB |
Output is correct |
6 |
Correct |
48 ms |
4692 KB |
Output is correct |
7 |
Correct |
14 ms |
2908 KB |
Output is correct |
8 |
Runtime error |
4 ms |
8540 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |