제출 #1184901

#제출 시각아이디문제언어결과실행 시간메모리
1184901tamyteJoker (BOI20_joker)C++20
31 / 100
2094 ms17584 KiB
#include <bits/stdc++.h> using namespace std; struct DSU { vector<int> e; DSU(int n) { e = vector<int>(n, -1); } int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } int size(int x) { return -e[get(x)]; } bool same(int x, int y) { return get(x) == get(y); } void unite(int x, int y) { x = get(x); y = get(y); if (x == y) return; if (e[x] > e[y]) swap(x, y); e[x] += e[y]; e[y] = x; } }; const int N = 2e5; vector<int> col(N + 1, -1); vector<bool> vis(N + 1); void bfs(bool& ok, int x, vector<vector<int>>& adj, int banned) { queue<int> q; vector<int> used = {x}; q.push(x); vis[x] = true; while (q.size()) { int v = q.front(); q.pop(); for (auto& u : adj[v]) { if (u == banned) continue; if (vis[u]) { if (col[v] == col[u]) { ok = true; break; } continue; } vis[u] = true; used.push_back(u); col[u] = col[v] ^ 1; q.push(u); } } for (auto& u : used) { vis[u] = false; } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; vector<pair<int, int>> a(m); for (int i = 0; i < m; ++i) { cin >> a[i].first >> a[i].second; a[i].first--; a[i].second--; } vector<int> ord(q); iota(begin(ord), end(ord), 0); vector<array<int, 2>> quer(q); for (int i =0 ; i < q; ++i) { for (int j = 0; j < 2; ++j) { cin >> quer[i][j]; quer[i][j]--; } } sort(begin(ord), end(ord), [&](const int x, const int y) { if (quer[x][0] != quer[x][0]) return quer[x][0] < quer[y][0]; return quer[x][1] > quer[y][1]; }); vector<vector<int>> ordq(200); for (int i = 0; i < q; ++i) { ordq[quer[ord[i]][0]].push_back(i); } vector<bool> res(q); for (int _ = 0; _ < 200; ++_) { vector<vector<int>> adj(n); int k = m - 1; int kl = 0; bool ok = false; DSU dsu(n); for (auto& u : col) u = -1; for (auto i : ordq[_]) { int j = ord[i]; int en = quer[j][1]; int enl = quer[j][0]; for (int l = kl; l < enl; ++l) { auto [x, y] = a[l]; adj[x].push_back(y); adj[y].push_back(x); if (dsu.same(x, y)) { if (col[x] == col[y]) { ok = true; } } else { if (dsu.size(x) < dsu.size(y)) swap(x, y); if (col[x] == -1) col[x] = 0; col[y] = col[x] ^ 1; bfs(ok, y, adj, x); dsu.unite(x, y); } } for (int l = k; l > en; --l) { auto [x, y] = a[l]; adj[x].push_back(y); adj[y].push_back(x); if (dsu.same(x, y)) { if (col[x] == col[y]) { ok = true; } } else { if (dsu.size(x) < dsu.size(y)) swap(x, y); if (col[x] == -1) col[x] = 0; col[y] = col[x] ^ 1; bfs(ok, y, adj, x); dsu.unite(x, y); } } kl = enl; k = en; res[j] = ok; } } for (auto u : res) { cout << (u == 1 ? "YES\n" : "NO\n"); } }
#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...