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;
#define N 200100
vector<int> adj[N];
int color[N];
int dfs(int x, int col) {
if(color[x]) {
if(col==color[x]) return 0;
else return 1;
}
color[x] = col;
for(auto i: adj[x])
if(dfs(i, 3-col))
return 1;
return 0;
}
int a[N], b[N];
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
for(int i = 0; i < m; i++)
cin >> a[i] >> b[i];
while(q--) {
int l, r;
cin >> l >> r;
memset(color, 0, sizeof color);
for(int i = 1; i <= n; i++)
adj[i].clear();
for(int i = 0; i < l-1; i++)
adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]);
for(int i = r; i < m; i++)
adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]);
for(int i = 0; i < n; i++) {
if(!color[i]){
if(dfs(i, 1)) {
cout << "YES\n";
break;
}
}
if(i==n-1) 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... |