Submission #536349

#TimeUsernameProblemLanguageResultExecution timeMemory
536349skittles1412Joker (BOI20_joker)C++17
0 / 100
85 ms4200 KiB
#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) { 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] = !pv; dbg(xu, xv, par[u], find(xu).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]; dbg(u, v); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...