Submission #929144

#TimeUsernameProblemLanguageResultExecution timeMemory
929144Joshua_AnderssonJoker (BOI20_joker)C++14
0 / 100
2027 ms6144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll const int inf = int(1e18); typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> p2; #define rep(i, high) for (int i = 0; i < high; i++) #define repp(i, low, high) for (int i = low; i < high; i++) #define repe(i, container) for (auto& i : container) #define sz(container) ((int)container.size()) inline void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } struct UF { vi size; vi par; vi parity; UF(int n) : size(n, 1), parity(n), par(n) { rep(i, n)par[i] = i; } int find(int x) { return x == par[x] ? x : find(par[x]); } int getparity(int x) { return x == par[x] ? parity[x] : parity[x] ^ getparity(par[x]); } bool oddcycle(int a, int b) { return getparity(a) == getparity(b); } void merge(int a, int b) { if (size[find(a)] < size[find(b)]) swap(a, b); int childa = a; a = find(a); b = find(b); if (a != b) { parity[b] ^= getparity(childa); size[a] += size[b]; par[b] = a; } } }; signed main() { fast(); int n, m, q; cin >> n >> m >> q; vector<p2> edgelist; rep(i, m) { int a, b; cin >> a >> b; a--; b--; edgelist.emplace_back(a, b); } while (q--) { int l, r; cin >> l >> r; l--; r--; UF uf(n); bool any = 0; rep(i, l) { int a, b; tie(a, b) = edgelist[i]; if (uf.find(a)==uf.find(b)) any |= uf.oddcycle(a, b); uf.merge(a, b); } repp(i, r+1, m) { int a, b; tie(a, b) = edgelist[i]; if (uf.find(a) == uf.find(b)) any |= uf.oddcycle(a, b); uf.merge(a, b); } cout << (any ? "YES" : "NO") << "\n"; } return 0; }

Compilation message (stderr)

Joker.cpp: In constructor 'UF::UF(ll)':
Joker.cpp:25:5: warning: 'UF::parity' will be initialized after [-Wreorder]
   25 |  vi parity;
      |     ^~~~~~
Joker.cpp:24:5: warning:   'vi UF::par' [-Wreorder]
   24 |  vi par;
      |     ^~~
Joker.cpp:27:2: warning:   when initialized here [-Wreorder]
   27 |  UF(int n) : size(n, 1), parity(n), par(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...