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;
signed main () {
int n, m;
cin >> n >> m;
int q;
cin >> q;
vector <pair <int,int>> edge;
vector <vector <int>> g(n);
vector <int> used(n, -1);
int f = 0;
function <void(int, int)> dfs=[&](int v, int color) {
used[v] = color;
for(auto i : g[v]) {
if(used[i] == -1) dfs(i, 1-color);
else {
if(used[i] == used[v]) f = 1;
}
}
};
function <int(int)> check=[&](int x) {
for(int i = x; i < m; i ++) {
g[edge[i].first].push_back(edge[i].second);
g[edge[i].second].push_back(edge[i].first);
}
f = 0;
for(int i = 0; i < n; i ++) {
if(used[i] == -1) dfs(i, 0);
}
for(auto &i : used) i = -1;
for(auto &i : g) i.clear();
if(f) return 1;
return 0;
};
for(int i = 0; i < m; i ++) {
int u, v;
cin >> u >> v;
u --, v--;
edge.push_back({u, v});
}
int l = 0, r = m-1;
while(l < r) {
int mid = (l + r + 1) / 2;
if(check(mid)) l = mid;
else r = mid - 1;
}
int gg = l;
// cout << gg + 1 << "\n";
while(q --) {
// int l, r;
cin >> l >> r;
l --, r --;
if(l == 0) {
if(r < gg) 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... |