Submission #571243

#TimeUsernameProblemLanguageResultExecution timeMemory
571243YouAreMyGalaxySwapping Cities (APIO20_swap)C++17
100 / 100
403 ms44560 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #include <swap.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5, M = 2e5, K = N + M, cbit = 18, oo = 1e9 + 1; int f[K + 1][cbit + 1], id[M + 1]; int n, m; int lab[K + 1], weight[K + 1], deg[K + 1], depth[K + 1]; bool able[K + 1]; vector<int> adj[K + 1]; int FindSet(int u) { return lab[u] < 0 ? u : lab[u] = FindSet(lab[u]); } void unite(int u, int v, int w) { bool ok = deg[u] > 1 | deg[v] > 1; ++deg[u]; ++deg[v]; u = FindSet(u); v = FindSet(v); if (u == v) { if (!able[u]) { able[u] = true; weight[u] = w; } return ; } ++n; able[n] = able[u] | able[v] | ok; if (able[n]) { weight[n] = w; } lab[u] = lab[v] = n; adj[n].push_back(u); adj[n].push_back(v); //cerr << n << ' ' << u << '\n'; //cerr << n << ' ' << v << '\n'; } void DFS(int u, int par) { if (par != 0 && !able[u]) { weight[u] = weight[par]; } //cerr << u << ' ' << weight[u] << '\n'; for (int v : adj[u]) { //cerr << u << ' ' << v << '\n'; depth[v] = depth[u] + 1; f[v][0] = u; for (int i = 1; i <= cbit; ++ i) { f[v][i] = f[f[v][i - 1]][i - 1]; } DFS(v, u); } } int get(int u, int v) { if (depth[v] < depth[u]) { swap(u, v); } int k = depth[v] - depth[u]; for (int i = cbit; i >= 0; -- i) { if ((k >> i) & 1) { v = f[v][i]; } } if (u == v) { //cerr << u << '\n'; return weight[u]; } for (int i = cbit; i >= 0; -- i) { if (f[u][i] != f[v][i]) { u = f[u][i]; v = f[v][i]; } } //cerr << f[u][0] << '\n'; return weight[f[u][0]]; } void init(int _n, int _m, vector<int> u, vector<int> v, vector<int> w) { n = _n; m = _m; iota(id, id + m, 0); memset(lab, -1, sizeof(lab)); memset(weight, -1, sizeof(weight)); sort(id, id + m, [&](const int &a, const int &b) { return w[a] < w[b]; }); for (int i = 0; i < m; ++ i) { unite(u[id[i]] + 1, v[id[i]] + 1, w[id[i]]); } DFS(n, 0); } int getMinimumFuelCapacity(int X, int Y) { return get(X + 1, Y + 1); } /*void read() { init(5, 6, {0, 0, 1, 1, 1, 2}, {1, 2, 2, 3, 4, 3}, {4, 4, 1, 2, 10, 3}); cout << getMinimumFuelCapacity(1, 2) << '\n'; cout << getMinimumFuelCapacity(2, 4) << '\n'; cout << getMinimumFuelCapacity(0, 1); init(3, 2, {0, 0}, {1, 2}, {5, 5}); cout << getMinimumFuelCapacity(1, 2); } void solve() { } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }*/

Compilation message (stderr)

swap.cpp: In function 'void unite(int, int, int)':
swap.cpp:20:22: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   20 |     bool ok = deg[u] > 1 | deg[v] > 1;
      |               ~~~~~~~^~~
#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...