Submission #575295

#TimeUsernameProblemLanguageResultExecution timeMemory
575295talant117408Joker (BOI20_joker)C++17
25 / 100
334 ms20620 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define pb push_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' const int N = 2e5+7; struct query { int l, r; int index; query() { l = r = 0; index = -1; } }; vector <pii> graph[N], edges; bool ans[N], odd_cycle = 0; int color[N], used[N]; int link[N], saizu[N]; int cnt, j; bool rev = 1; int find(int n) { if (link[n] == n) return n; return link[n] = find(link[n]); } void dfs(int v, int c); void unite(int a, int b) { if (find(a) == find(b)) { if (color[a] == color[b]) odd_cycle = 1; return; } if (saizu[find(a)] < saizu[find(b)]) swap(a, b); saizu[find(a)] += saizu[find(b)]; link[find(b)] = find(a); if (saizu[find(a)] == 1) { dfs(a, 0); } else { used[a] = cnt*2; dfs(b, color[a]^1); } } void dfs(int v, int c) { used[v] = cnt*2-1; color[v] = c; for (auto to : graph[v]) { if (rev == 0) { if (find(v) != find(to.first) || to.second <= j) continue; } else { if (find(v) != find(to.first) || to.second >= j) continue; } if (used[to.first] < cnt*2-1) { dfs(to.first, c^1); } else if (color[to.first] == color[v]) { odd_cycle = 1; } } used[v] = cnt*2; } void solve() { int n, m, q; cin >> n >> m >> q; vector <query> queries(q+1); edges.pb(mp(0, 0)); for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); edges.pb(mp(a, b)); graph[a].pb(mp(b, i)); graph[b].pb(mp(a, i)); } for (int i = 1; i <= q; i++) { cin >> queries[i].l >> queries[i].r; queries[i].index = i; } sort(queries.begin()+1, queries.end(), [&](query a, query b) { if (a.l == b.l) return a.r < b.r; return a.l < b.l; }); for (int i = q; i; i--) { if (i == q || queries[i].l != queries[i+1].l) { j = m; odd_cycle = 0; for (int l = 1; l <= n; l++) { link[l] = l; saizu[l] = 1; used[l] = 0; color[l] = -1; } rev = 1; j = queries[i].l; for (int l = 1; l < queries[i].l; l++) { cnt++; unite(edges[l].first, edges[l].second); } j = m; rev = 0; } while (j && j > queries[i].r) { cnt++; unite(edges[j].first, edges[j].second); j--; } ans[queries[i].index] = odd_cycle; } for (int i = 1; i <= q; i++) { cout << (ans[i] ? "YES" : "NO") << endl; } } int main() { //~ do_not_disturb int t = 1; //~ cin >> t; while (t--) { solve(); } return 0; } /* 6 8 8 1 3 1 5 1 6 2 5 2 6 3 4 3 5 5 6 1 3 1 7 1 5 1 1 1 6 1 4 1 2 1 8 6 8 6 1 3 1 5 1 6 2 5 2 6 3 4 3 5 5 6 1 5 2 5 3 5 4 5 6 7 6 8 */
#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...