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;
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
// #define cin fin
// #define cout fout
// const string FILE_NAME = ""; ifstream fin(FILE_NAME + ".in"); ofstream fout(FILE_NAME + ".out");
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
vector<vi> adj;
vi edges, good;
vi color;
bool cycle = false;
void dfs(int u, int p, int c){
if(color[u] != -1 && color[u] != c){
cycle = true;
return;
}
if(color[u] != -1)
return;
color[u] = c;
trav(id, adj[u]){
if(!good[id]) continue;
int v = edges[id] ^ u;
if(v == p)
continue;
dfs(v, u, c ^ 1);
}
}
void solve(){
int n, m, q;
cin >> n >> m >> q;
adj.resize(n);
edges.resize(m);
F0R(i, m){
int a, b;
cin >> a >> b;
--a, --b;
edges[i] = a ^ b;
adj[a].pb(i);
adj[b].pb(i);
}
color.resize(n);
good.resize(m);
auto f = [&](int a, int b){
color = vector<int>(n, -1);
F0R(i, m){
if(i >= a && i <= b)
good[i] = false;
else good[i] = true;
}
cycle = false;
F0R(i, n){
if(color[i] == -1)
dfs(i, -1, 1);
}
return cycle;
};
vector<array<int, 3>> queries(q);
F0R(i, q){
cin >> queries[i][0] >> queries[i][1];
queries[i][0]--, queries[i][1]--;
queries[i][2] = i;
}
sort(all(queries), [&](array<int, 3>& a, array<int, 3>& b) {return a[1] < b[1];});
int l = 0, r = q - 1, point = -1;
while(l <= r){
int m = (l + r) / 2;
if(f(queries[m][0], queries[m][1])){
point = m;
l = m + 1;
}
else{
r = m - 1;
}
}
if(point == -1){
F0R(i, q){
cout << "NO\n";
}
}
else{
F0R(i, point + 1)
queries[i][0] = 1;
FOR(i, point + 1, q)
queries[i][0] = 0;
sort(all(queries), [&](array<int, 3>& a, array<int, 3>& b){return a[2] < b[2];});
F0R(i, q){
if(queries[i][0] == 1)
cout << "YES\n";
else cout << "NO\n";
}
}
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int TC = 1;
// cin >> TC;
while(TC--){
solve();
}
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... |