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;
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 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... |