Submission #930540

#TimeUsernameProblemLanguageResultExecution timeMemory
930540Ghulam_JunaidJoker (BOI20_joker)C++17
39 / 100
2094 ms211884 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; int n, m, q, vis_nq[N], par[N], col[N]; vector<pair<int, int>> g[N], atl[N]; pair<int, int> edge[N]; vector<int> S[N]; bool ans[N]; int root(int v){ return (par[v] == -1 ? v : root(par[v])); } inline bool merge(int u, int v){ int r1 = root(u); int r2 = root(v); if (r1 == r2) return (col[u] != col[v]); if (S[r2].size() > S[r1].size()) swap(r1, r2); par[r2] = r1; int take = 0; if (col[u] == col[v]) take = 3; for (int x : S[r2]){ col[x] ^= take; S[r1].push_back(x); } S[r2].clear(); return 1; } int main(){ scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= m; i ++){ int u, v; scanf("%d%d", &u, &v); g[u].push_back({i, v}); g[v].push_back({i, u}); edge[i] = {u, v}; } int mx = 0; for (int i = 0; i < q; i ++){ int l, r; scanf("%d%d", &l, &r); mx = max(mx, l); atl[l].push_back({r, i}); } for (int i = 1; i <= m; i ++){ sort(atl[i].begin(), atl[i].end()); reverse(atl[i].begin(), atl[i].end()); } for (int i = 1; i <= mx; i ++){ if (atl[i].size() == 0) continue; for (int j = 1; j <= n; j ++){ S[j] = {j}; par[j] = -1; col[j] = 1; } bool even = 1; for (int j = 1; j < i; j ++) even &= merge(edge[j].first, edge[j].second); int x = m; for (auto [r, id] : atl[i]){ for (int j = r + 1; j <= x; j ++) even &= merge(edge[j].first, edge[j].second); x = r; if (even) ans[id] = 0; else ans[id] = 1; } } for (int i = 0; i < q; i ++){ if (ans[i]) printf("YES\n"); else printf("NO\n"); } }

Compilation message (stderr)

Joker.cpp: In function 'int main()':
Joker.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d%d%d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
Joker.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%d%d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~
#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...