# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
518539 | thegrimbee | Experimental Charges (NOI19_charges) | C++14 | 36 ms | 4848 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int p[2*1000005]; ///parent
int height[1000005]; ///height
void reset(int N){
for(int i = 0;i <= N;i++){
p[i] = i; ///all sets are disjoint
height[i] = 1;
}
}
int findSet(int u){
if(u == p[u]) return u; ///representative
else{
p[u] = findSet(p[u]); ///search upwards
return p[u];
}
}
void unionSet(int a, int b){
///find represenative of a and b
int A = findSet(a);
int B = findSet(b);
if(A == B) return;
if(height[A] < height[B]){
p[A] = B;
}
else{
p[B] = A;
if(height[A] == height[B]) height[A]++;
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, Q;
char T;
int a , b, temp1, temp2, temp3, temp4;
cin >> N >> Q;
reset(2*(N+1));
for (int i = 0; i < Q; ++i){
cin >> T >> a >> b;
if (T == 'Q'){
temp1 = findSet(a);
temp2 = findSet(b);
temp3 = findSet(a+N);
temp4 = findSet(b+N);
if (temp1 == temp2 && temp1 == temp4)cout << "?\n";
else if (temp1 == temp2)cout << "R\n";
else if (temp1 == temp4)cout << "A\n";
else cout << "?\n";
}
else if (T == 'A'){
unionSet(a, b + N);
unionSet(a+N, b);
}
else{
unionSet(a, b);
unionSet(a+N, b+N);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |