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>
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
using namespace std;
const int N = 2e5+10;
int n,m,p[N],sz[N],lz[N],q;
pii ad[N];
int pa(int v,int &c)
{
c ^= lz[v];
if(p[v] == v) return v;
return pa(p[v] , c);
}
void join(int a,int b)
{
int ca = 0;
int cb = 0;
a = pa(a,ca);
b = pa(b,cb);
if(a != b)
{
if(sz[a] < sz[b]) swap(a,b);
sz[a] += sz[b];
p[b] = a;
if(ca == cb) lz[b] = 1;
}
}
bool check(int a,int b)
{
int ca = 0;
int cb = 0;
a = pa(a,ca);
b = pa(b,cb);
if(a == b && ca == cb) return true;
return false;
}
bool qu(int l,int r)
{
forinc(i,1,n)
{
sz[i] = 1;
p[i] = i;
}
for(int i=1;i<=m;i++)
{
if(l<=i && i<=r) continue;
if(check(ad[i].fi , ad[i].se)) return true;
join(ad[i].fi , ad[i].se);
}
return false;
}
int32_t main()
{
if(fopen("task.inp","r"))
{
freopen("task.inp","r",stdin);
freopen("task.out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>q;
forinc(i,1,m)
{
int x,y;
cin>>x>>y;
ad[i] = {x,y};
}
while(q--)
{
int l,r;
cin>>l>>r;
cout<< (qu(l,r) ? "YES\n" : "NO\n");
}
}
Compilation message (stderr)
Joker.cpp: In function 'int32_t main()':
Joker.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen("task.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen("task.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |