이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct DSU {
vector<int> size, link;
vector<bool> added;
DSU(int sz) {
size.resize(sz+1);
link.resize(sz+1);
added.resize(sz+1);
iota(link.begin(), link.end(), 0);
}
int find(int x) {
while (x != link[x]) x = link[x];
return x;
}
bool same(int a, int b) {
return find(a) == find(b);
}
void unite(int a, int b) {
added[a] = true, added[b] = true;
a = find(a);
b = find(b);
if (a == b) return;
if (size[a] < size[b]) swap(a, b);
size[a] += size[b];
link[b] = a;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, q;
cin >> n >> q;
DSU d(n);
while (q--) {
char c;
int a, b;
cin >> c >> a >> b;
if (c == 'R') d.unite(a, b);
else if (c == 'A') d.added[a] = true, d.added[b] = true;
else if (c == 'Q') {
if (d.same(a, b)) cout << "R\n";
else if (d.added[a] && d.added[b]) cout << "A\n";
else cout << "?\n";
}
}
return 0;
}
# | 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... |