#include<bits/stdc++.h>
using namespace std;
vector<int> adj[200005];
vector<pair<int, int> > arr[200005];
int color[200005], ans[200005], a[200005], b[200005], n, m, q;
int dfs(int u, int c) {
if(color[u]) {
if(c == color[x]) return 0;
else return 1;
}
color[u] = c;
for(auto v : adj[u]) if(dfs(v, 3 - c)) return 1;
return 0;
}
bool check(int l, int r) {
memset(color, 0, sizeof color);
for(int i = 1; i <= n; i++) adj[i].clear();
for(int i = 0; i < l; i++) adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]);
for(int i = r + 1; 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)) return 1;
return 0;
}
int main() {
cin.sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m >> q;
for(int i = 0; i < m; i++) cin >> a[i] >> b[i];
for(int e = 0; e < q; e++) {
int l, r;
cin >> l >> r;
arr[l - 1].push_back({r - 1, e});
}
for(int i = 0; i < m; i++) {
sort(arr[i].begin(), arr[i].end());
int l = 0, r = arr[i].size();
while(l < r) {
int mid = l + r >> 1;
if(check(i, arr[i][mid].first)) l = mid + 1;
else r = mid;
}
for(int j = 0; j < l; j++) ans[arr[i][j].second] = 1;
for(int j = l; j < arr[i].size(); j++) ans[arr[i][j].second] = 0;
}
for(int i = 0; i < q; i++) cout << (ans[i] ? "YES\n":"NO\n");
}
Compilation message
Joker.cpp: In function 'int dfs(int, int)':
Joker.cpp:10:23: error: 'x' was not declared in this scope
10 | if(c == color[x]) return 0;
| ^
Joker.cpp: In function 'int main()':
Joker.cpp:40:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int mid = l + r >> 1;
| ~~^~~
Joker.cpp:45:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int j = l; j < arr[i].size(); j++) ans[arr[i][j].second] = 0;
| ~~^~~~~~~~~~~~~~~