#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;
int 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;
}
Compilation message
servers.cpp: In function 'int dfs(int, int, int, int)':
servers.cpp:18:1: warning: no return statement in function returning non-void [-Wreturn-type]
18 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
3752 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
3752 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
3700 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
3700 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
3760 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
3760 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
3756 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
3756 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
3740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
3740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
3664 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
3664 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |