# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1224638 | sokratisi | Inside information (BOI21_servers) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int n, q, a, b;
char c;
set<int> table[125000]; // table[{i, j}] does i have j
int cq[125000];
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) table[i].insert(i);
for (int i = 0; i < n + q - 1; i++) {
scanf("%c", &c); scanf("%c", &c);
if (c == 'S') {
scanf("%d%d", &a, &b);
for (auto u: table[a]) {
table[b].insert(u);
cq[u]++;
}
for (auto u: table[b]) {
table[a].push_back(u);
cq[u]++;
}
}
if (c == 'Q') {
scanf("%d%d", &a, &b); // does a have d
if (table[a].find(b) != table[a].end()) printf("yes\n");
else printf("no\n");
}
if (c == 'C') {
scanf("%d", &a);
printf("%d\n", cq[a] + 1);
}
}
return 0;
}