#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll,ll>
#define all(x) (x).begin(),(x).end()
const int maxn=2e5+10;
vector<pi> edges(maxn);
vi nums(maxn,maxn);
vi head(maxn);
vi flip(maxn,0);
vi sze(maxn,1);
vector<vi> changes;
int m;
bool ok=1;
pi get(int a) {
if (a==head[a]) {
return {a,0};
}
pi temp=get(head[a]);
return {temp.fi,temp.se^flip[a]};
}
void unite(int a, int b) {
int f1,f2;
tie(a,f1)=get(a);
tie(b,f2)=get(b);
if (a==b) {
if (f1==f2 && ok) {
changes.pb({1});
ok=0;
}
return;
}
if (sze[a]<sze[b]) {
swap(a,b);
swap(f1,f2);
}
changes.pb({b,head[b],flip[b],a,sze[a]});
head[b]=a;
flip[b]=f1^f2^1;
sze[a]=max(sze[a],sze[b]+1);
}
void rollback(int a) {
while (changes.size()>a) {
if (changes.back().size()==1) {
ok=1;
}
else {
head[changes.back()[0]]=changes.back()[1];
flip[changes.back()[0]]=changes.back()[2];
sze[changes.back()[3]]=changes.back()[4];
}
changes.pop_back();
}
}
void dfs(int l, int r, int tl, int tr) {
if (tr<tl) {
return;
}
int sze=changes.size();
int tm=tl+(tr-tl)/2;
int ttl=l,ttr=r,tttr=r;
while (l<tm) {
unite(edges[l].fi,edges[l].se);
l++;
}
while (r>=l && ok) {
unite(edges[r].fi,edges[r].se);
r--;
}
nums[tm]=r;
rollback(sze);
while (ttr>r) {
unite(edges[ttr].fi,edges[ttr].se);
ttr--;
}
dfs(ttl,ttr,tl,tm-1);
rollback(sze);
while (ttl<l) {
unite(edges[ttl].fi,edges[ttl].se);
ttl++;
}
dfs(ttl,tttr,tm+1,tr);
rollback(sze);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
iota(all(head),0);
int n,m,q;
cin >> n >> m >> q;
for (int i=0; i<m; i++) {
cin >> edges[i].fi >> edges[i].se;
edges[i].fi--;
edges[i].se--;
}
dfs(0,m-1,0,m-1);
int a,b;
for (int i=0; i<q; i++) {
cin >> a >> b;
a--;
b--;
if (b<=nums[a]) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
return 0;
}
# | 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... |