# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
486164 | niloyroot | Experimental Charges (NOI19_charges) | C++14 | 29 ms | 3404 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
const ll mod = 1000000007;
void solve(){
ll n; cin>>n;
ll q; cin>>q;
ll par[n+1];
ll sz[n+1];
bool col[n+1]; // whether it attracts it's parent or not;
forp(i,1,n){
par[i]=i;
sz[i]=1;
col[i]=0;
}
char c; ll a,b,x,y; bool currA,currB;
forp(i,1,q){
cin>>c>>a>>b;
x=a;y=b;
if(c!='Q'){
currA=(c=='A'); currB=0;
while(a!=par[a]){
currA=(col[a]==1)?(currA^1):currA;
a=par[a];
}
while(b!=par[b]){
currB=(col[b]==1)?(currB^1):currB;
b=par[b];
}
if(a==b){continue;}
if(sz[a]<sz[b]){swap(a,b);}
sz[a]+=sz[b];
par[b]=a;
col[b]=(currA!=currB);
} else {
currA=currB=0;
while(a!=par[a]){
currA=(col[a]==0)?currA:(currA^1);
a=par[a];
}
while(b!=par[b]){
currB=(col[b]==0)?currB:(currB^1);
b=par[b];
}
if(a!=b){
cout<<'?'<<newl;
} else {
if(currA!=currB){
cout<<"A"<<newl;
} else {
cout<<"R"<<newl;
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1; //cin>>t;
while(t--)solve();
}
컴파일 시 표준 에러 (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... |