#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 4005;
vector<tuple<int, int, int>> queries;
vector<pair<int, int>> ad[mxN];
bool vis[mxN];
int cnt = 0;
void dfs(int u, int p, int last, int lim) {
vis[u] = true;
cnt++;
for (auto [v, ee] : ad[u]) {
if (ee >= lim || v == p || last > ee) continue;
dfs(v, u, ee, lim);
}
}
void testCase() {
int n, q;
cin >> n >> q;
int cur_edge = 0;
for (int i = 0; i < n + q - 1; i++) {
char c;
cin >> c;
if (c == 'S') {
int u, v;
cin >> u >> v;
ad[u].push_back({v, cur_edge});
ad[v].push_back({u, cur_edge});
cur_edge++;
} else if (c == 'Q') {
int u, v;
cin >> u >> v;
queries.push_back({u, v, cur_edge});
} else {
int u;
cin >> u;
queries.push_back({0, u, cur_edge});
}
}
for (auto [u, v, ee] : queries) {
dfs(v, -1, -1, ee);
if (u) {
cout << (vis[u] ? "yes\n" : "no\n");
} else {
cout << cnt << "\n";
}
memset(vis, 0, sizeof vis);
cnt = 0;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2276 KB |
Output is correct |
2 |
Correct |
48 ms |
2392 KB |
Output is correct |
3 |
Correct |
137 ms |
2468 KB |
Output is correct |
4 |
Correct |
47 ms |
2316 KB |
Output is correct |
5 |
Correct |
46 ms |
2440 KB |
Output is correct |
6 |
Correct |
1639 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2276 KB |
Output is correct |
2 |
Correct |
48 ms |
2392 KB |
Output is correct |
3 |
Correct |
137 ms |
2468 KB |
Output is correct |
4 |
Correct |
47 ms |
2316 KB |
Output is correct |
5 |
Correct |
46 ms |
2440 KB |
Output is correct |
6 |
Correct |
1639 ms |
2540 KB |
Output is correct |
7 |
Correct |
38 ms |
2260 KB |
Output is correct |
8 |
Correct |
49 ms |
2232 KB |
Output is correct |
9 |
Correct |
286 ms |
2468 KB |
Output is correct |
10 |
Correct |
46 ms |
2252 KB |
Output is correct |
11 |
Correct |
56 ms |
2344 KB |
Output is correct |
12 |
Correct |
1695 ms |
2412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
2264 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
2264 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
2244 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
2244 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
2296 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
2296 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
2236 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
2236 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
2228 KB |
Output is correct |
2 |
Correct |
47 ms |
2256 KB |
Output is correct |
3 |
Correct |
168 ms |
2460 KB |
Output is correct |
4 |
Correct |
48 ms |
2328 KB |
Output is correct |
5 |
Correct |
45 ms |
2412 KB |
Output is correct |
6 |
Correct |
1555 ms |
2440 KB |
Output is correct |
7 |
Correct |
47 ms |
2268 KB |
Output is correct |
8 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
2228 KB |
Output is correct |
2 |
Correct |
47 ms |
2256 KB |
Output is correct |
3 |
Correct |
168 ms |
2460 KB |
Output is correct |
4 |
Correct |
48 ms |
2328 KB |
Output is correct |
5 |
Correct |
45 ms |
2412 KB |
Output is correct |
6 |
Correct |
1555 ms |
2440 KB |
Output is correct |
7 |
Correct |
47 ms |
2268 KB |
Output is correct |
8 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |