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
using namespace std;
int n,m,q,l,r;
bool b;
vector<pair<int,int>>adj[2005];
bool vis[2005];
int d[2005];
void dfs(int node,int par,int de)
{
if(b)return;
d[node]=de;
vis[node]=1;
for(auto u:adj[node])
{
if(u.second>=l&&u.second<=r)continue;
if(u.first==par)continue;
if(vis[u.first]&&(de-d[u.first])%2==0){b=1;break;}
if(!vis[u.first])
{
dfs(u.first,node,de+1);
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=m;i++)
{
int a,b;
cin>>a>>b;
adj[a].push_back({b,i});
adj[b].push_back({a,i});
}
while(q--)
{
b=0;
memset(vis,0,sizeof(vis));
memset(d,0,sizeof(d));
cin>>l>>r;
for(int i=1;i<n;i++)
{
if(!vis[i])dfs(i,i,1);
if(b)break;
}
if(b)cout<<"YES"<<'\n';
else cout<<"NO"<<'\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... |