Submission #536346

#TimeUsernameProblemLanguageResultExecution timeMemory
536346skittles1412Joker (BOI20_joker)C++17
0 / 100
72 ms7456 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()) namespace s1 { const int maxn = 2e3 + 5; int bl, br, vis[maxn]; bool bad; vector<pair<int, int>> graph[maxn]; void dfs(int u, int b) { if (vis[u]) { bad |= vis[u] != b; return; } vis[u] = b; for (auto& [v, i] : graph[u]) { if (i < bl || br < i) { dfs(v, b ^ 1); } } } void solve(int n, int m, int q) { for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; graph[u].emplace_back(v, i); graph[v].emplace_back(u, i); } while (q--) { cin >> bl >> br; bl--; br--; bad = false; memset(vis, 0, sizeof(vis)); for (int i = 0; i < n; i++) { if (!vis[i]) { dfs(i, 0); } } if (bad) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } } // namespace s1 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); } p[v] += p[u]; p[u] = v; par[u] ^= 1; } }; 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() { 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...