#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define vb vector<bool>
#define vi vector<int>
#define vpii vector<pii>
#define vvb vector<vb>
#define vvi vector<vi>
#define vvpii vector<vpii>
void dfs(vvpii & adj, int v, int t, int source, vvb & reachable) {
reachable[source][v] = true;
for (pii e : adj[v]) {
if (e.second < t) dfs(adj, e.first, e.second, source, reachable);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int N, K;
cin >> N >> K;
int last = 0;
vi added(N, INT_MAX);
added[0] = 0;
for (int t = 1; t < N + K; ++t) {
string command;
cin >> command;
if (command == "S") {
int a, b;
cin >> a >> b;
--a; --b;
if (a > b) swap(a, b);
added[b] = ++last;
} else if (command == "Q") {
int a,d;
cin >> a >> d;
--a; --d;
if (a == d) cout << "yes\n";
else if (added[a] != INT_MAX && added[d] != INT_MAX && (a == 0 || added[d] <= added[a])) cout << "yes\n";
else cout << "no\n";
} else {
int d;
cin >> d;
--d;
int cnt = 1;
if (d == 0) {
cnt += last;
} else {
if (added[d] != INT_MAX) {
cnt += last - added[d] + 1;
}
}
cout << cnt << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
1556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
1556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1528 KB |
Output is correct |
2 |
Correct |
61 ms |
4016 KB |
Output is correct |
3 |
Correct |
62 ms |
4044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1528 KB |
Output is correct |
2 |
Correct |
61 ms |
4016 KB |
Output is correct |
3 |
Correct |
62 ms |
4044 KB |
Output is correct |
4 |
Correct |
31 ms |
1456 KB |
Output is correct |
5 |
Correct |
86 ms |
3832 KB |
Output is correct |
6 |
Correct |
49 ms |
3136 KB |
Output is correct |
7 |
Correct |
54 ms |
3172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |