Submission #313927

#TimeUsernameProblemLanguageResultExecution timeMemory
313927vipghn2003Joker (BOI20_joker)C++14
14 / 100
2093 ms14576 KiB
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; int n,m,q,p[N],a[N],u[N],v[N]; vector<int>comp[N]; bool kt; int Find(int u) { if(u==p[u]) return u; return p[u]=Find(p[u]); } void Union(int u,int v) { bool same=false; if(a[u]==a[v]) same=true; int x=Find(u); int y=Find(v); if(x==y&&same) kt=false; if(x==y) return ; if(comp[x].size()>comp[y].size()) swap(x,y); p[x]=y; for(auto&node:comp[x]) { comp[y].push_back(node); if(same) a[node]^=1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m>>q; for(int i=1;i<=m;i++) cin>>u[i]>>v[i]; while(q--) { int l,r; cin>>l>>r; for(int i=1;i<=n;i++) { p[i]=i; a[i]=0; comp[i].clear(); comp[i].push_back(i); } kt=true; for(int i=1;i<l;i++) Union(u[i],v[i]); for(int i=m;i>r;i--) Union(u[i],v[i]); if(kt) cout<<"NO"<<'\n'; else cout<<"YES"<<'\n'; } }
#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...