# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486164 | niloyroot | Experimental Charges (NOI19_charges) | C++14 | 29 ms | 3404 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
}
Compilation message (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... |