#include <bits/stdc++.h>
using namespace std;
const int N = 10'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 |
105 ms |
2496 KB |
Output is correct |
2 |
Correct |
95 ms |
2512 KB |
Output is correct |
3 |
Correct |
178 ms |
2756 KB |
Output is correct |
4 |
Correct |
92 ms |
2516 KB |
Output is correct |
5 |
Correct |
102 ms |
2568 KB |
Output is correct |
6 |
Correct |
1283 ms |
2580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
2496 KB |
Output is correct |
2 |
Correct |
95 ms |
2512 KB |
Output is correct |
3 |
Correct |
178 ms |
2756 KB |
Output is correct |
4 |
Correct |
92 ms |
2516 KB |
Output is correct |
5 |
Correct |
102 ms |
2568 KB |
Output is correct |
6 |
Correct |
1283 ms |
2580 KB |
Output is correct |
7 |
Incorrect |
80 ms |
2388 KB |
Extra information in the output file |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
2404 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
2404 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
2580 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
2580 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
2500 KB |
Output is correct |
2 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
2500 KB |
Output is correct |
2 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
2496 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
2496 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
2632 KB |
Output is correct |
2 |
Correct |
111 ms |
2516 KB |
Output is correct |
3 |
Correct |
176 ms |
2760 KB |
Output is correct |
4 |
Correct |
96 ms |
2428 KB |
Output is correct |
5 |
Correct |
101 ms |
2724 KB |
Output is correct |
6 |
Correct |
1411 ms |
2580 KB |
Output is correct |
7 |
Correct |
93 ms |
2608 KB |
Output is correct |
8 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
2632 KB |
Output is correct |
2 |
Correct |
111 ms |
2516 KB |
Output is correct |
3 |
Correct |
176 ms |
2760 KB |
Output is correct |
4 |
Correct |
96 ms |
2428 KB |
Output is correct |
5 |
Correct |
101 ms |
2724 KB |
Output is correct |
6 |
Correct |
1411 ms |
2580 KB |
Output is correct |
7 |
Correct |
93 ms |
2608 KB |
Output is correct |
8 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |