This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |