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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
const int maxn = 2e5 + 5;
struct DSU {
bool bip;
vector<int> p, par;
explicit DSU(int n) : bip(true), p(n, -1), par(n) {}
pair<int, bool> find(int u) {
if (p[u] < 0) {
return {u, false};
}
auto [v, vp] = find(p[u]);
p[u] = v;
par[u] ^= vp;
return {p[u], par[u]};
}
void merge(int xu, int xv) {
dbg(xu, xv);
auto [u, pu] = find(xu);
auto [v, pv] = find(xv);
if (u == v) {
bip &= pu != pv;
return;
}
if (p[u] < p[v]) {
swap(u, v);
swap(pu, pv);
}
dbg(u, pu, v, pv);
p[v] += p[u];
p[u] = v;
par[u] = pu ^ pv ^ 1;
dbg(xu, xv, par[u], find(xu).second);
assert(find(xu).second != find(xv).second);
}
};
int n, m;
vector<pair<int, int>> edges;
int solve(int ol) {
DSU dsu(n);
for (int i = 0; i < ol; i++) {
auto& [u, v] = edges[i];
dsu.merge(u, v);
}
for (int i = m - 1; i >= ol; i--) {
auto& [u, v] = edges[i];
dsu.merge(u, v);
if (!dsu.bip) {
return i;
}
}
return -1;
}
void solve() {
// DSU dsu(3);
// dsu.merge(1, 0);
// dsu.merge(1, 2);
// dsu.merge(1, 2);
// dbg(dsu.bip);
int q;
cin >> n >> m >> q;
edges.resize(m);
for (auto& [u, v] : edges) {
cin >> u >> v;
u--;
v--;
}
int ans[n];
fill(ans, ans + n, -1e9);
while (q--) {
int l, r;
cin >> l >> r;
l--;
r--;
if (ans[l] == -1e9) {
ans[l] = solve(l);
}
dbg(ans[l]);
if (r < ans[l]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# | 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... |