# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
858296 | Trisanu_Das | Joker (BOI20_joker) | C++17 | 0 ms | 0 KiB |
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;
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[x]) {
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");
}