#include <bits/stdc++.h>
using namespace std;
const int N = 5'000 + 10;
int n, k;
vector<pair<int, int>> ad[N];
vector<tuple<int, int, int>> Q;
int f[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i < n + k; ++i) {
char type; cin >> type;
if (type == 'S') {
int a, b; cin >> a >> b;
ad[a].push_back({b, i});
ad[b].push_back({a, i});
}
if (type == 'Q') {
int a, d; cin >> a >> d;
Q.emplace_back(a, d, i);
}
if (type == 'C') {
int d; cin >> d;
Q.emplace_back(0, d, i);
}
}
auto bfs = [&](int st, int ed, int time) {
memset(f, 0, sizeof f);
queue<int> q({st});
while (q.size()) {
auto u = q.front(); q.pop();
if (u == ed) return true;
for (const auto& [v, w] : ad[u]) {
if (w > time) continue;
if (f[u] < w) {
f[v] = w;
q.push(v);
}
}
}
return false;
};
for (const auto& [a, d, i] : Q) {
if (!a) continue;
cout << (bfs(d, a, i) ? "yes" : "no") << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
2256 KB |
Output is correct |
2 |
Correct |
61 ms |
2272 KB |
Output is correct |
3 |
Correct |
153 ms |
2624 KB |
Output is correct |
4 |
Correct |
60 ms |
2520 KB |
Output is correct |
5 |
Correct |
67 ms |
2560 KB |
Output is correct |
6 |
Correct |
1264 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
2256 KB |
Output is correct |
2 |
Correct |
61 ms |
2272 KB |
Output is correct |
3 |
Correct |
153 ms |
2624 KB |
Output is correct |
4 |
Correct |
60 ms |
2520 KB |
Output is correct |
5 |
Correct |
67 ms |
2560 KB |
Output is correct |
6 |
Correct |
1264 ms |
2540 KB |
Output is correct |
7 |
Incorrect |
53 ms |
2260 KB |
Extra information in the output file |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
2420 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
2420 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
2256 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
2256 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2300 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2300 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2256 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2256 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2436 KB |
Output is correct |
2 |
Correct |
60 ms |
2276 KB |
Output is correct |
3 |
Correct |
141 ms |
2504 KB |
Output is correct |
4 |
Correct |
58 ms |
2496 KB |
Output is correct |
5 |
Correct |
69 ms |
2564 KB |
Output is correct |
6 |
Correct |
1233 ms |
2532 KB |
Output is correct |
7 |
Correct |
56 ms |
2500 KB |
Output is correct |
8 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2436 KB |
Output is correct |
2 |
Correct |
60 ms |
2276 KB |
Output is correct |
3 |
Correct |
141 ms |
2504 KB |
Output is correct |
4 |
Correct |
58 ms |
2496 KB |
Output is correct |
5 |
Correct |
69 ms |
2564 KB |
Output is correct |
6 |
Correct |
1233 ms |
2532 KB |
Output is correct |
7 |
Correct |
56 ms |
2500 KB |
Output is correct |
8 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |