Submission #876701

#TimeUsernameProblemLanguageResultExecution timeMemory
876701huynhyen1609Experimental Charges (NOI19_charges)C++14
100 / 100
35 ms10708 KiB
#include<bits/stdc++.h> using namespace std; #define NAME "hattichdien" //#define int long long const int N=2e5; int n,q,p[N+5],a[N+5]; vector<int>vec[N+5]; int find(int v) { if(p[v]==0)return v; return p[v]=find(p[v]); } void union_(int u,int v,int c) { int x=u,y=v; u=find(u);v=find(v); if(u==v)return; if(vec[u].size()<vec[v].size()) { swap(u,v); swap(x,y); } p[v]=u; for(int i:vec[v])vec[u].push_back(i); if(c!=(a[x]^a[y]))for(int i:vec[v])a[i]=1-a[i]; } main() { ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0); //freopen(""NAME".inp","r",stdin); //freopen(""NAME".out","w",stdout); cin>>n>>q; for(int i=1;i<=n;++i) { a[i]=1; vec[i].push_back(i); } while(q--) { char c; int x,y; cin>>c>>x>>y; if(c=='R')union_(x,y,0); if(c=='A')union_(x,y,1); if(c=='Q') { if(find(x)!=find(y))cout<<"?\n"; else { if(a[x]^a[y])cout<<"A\n"; else cout<<"R\n"; } } } }

Compilation message (stderr)

charges.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...