# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
975956 | 2024-05-06T03:58:34 Z | josanneo22 | Swapping Cities (APIO20_swap) | C++17 | 2000 ms | 6820 KB |
#include "swap.h" #include <vector> #include <bits/stdc++.h> using namespace std; struct dsu { vector<int> fa, sz, mx_deg; dsu(int n) { fa.resize(n + 10); iota(fa.begin(), fa.end(), 0); sz.assign(n + 10, 1); mx_deg.assign(n + 10, 0); } int find(int x) { while (x != fa[x]) x = fa[x] = fa[fa[x]]; return x; } bool merge(int x, int y) { int px = find(x), py = find(y); if (px == py) return false; if (sz[py] > sz[px]) swap(px, py); sz[px] += sz[py]; fa[py] = px; mx_deg[px] = max(mx_deg[px], mx_deg[py]); return true; } bool same(int x, int y) { int px = find(x), py = find(y); return px == py; } }; vector<pair<int, pair<int, int>>> edges; int n; void init(int _N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) { n = _N; for (int i = 0; i < M; i++) edges.push_back(make_pair(W[i], make_pair(U[i], V[i]))); sort(edges.begin(), edges.end()); } int getMinimumFuelCapacity(int X, int Y) { // cout << "++++++++++++++++\n"; bool flag = true; dsu D(n); vector<int> deg(n + 1); for (int i = 0; i < edges.size(); i++) { int w = edges[i].first; int u = edges[i].second.first, v = edges[i].second.second; // cout << w << ' ' << u << ' ' << v << '\n'; for (int t = 0; t < 2; t++) { if (!flag && X != u && D.same(X, u) && D.same(X, Y) && D.same(u, Y)) return w; swap(u, v); } D.merge(u, v); deg[u]++; deg[v]++; if (deg[u] >= 3 || deg[v] >= 3) { D.mx_deg[D.find(u)] = 3; } if (D.mx_deg[D.find(X)] >= 3 && D.same(X, Y)) return w; if (flag && D.same(X, Y)) { flag = false; continue; } } return -1; } // #include "grader.cpp"
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 1 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Execution timed out | 2068 ms | 6820 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 1 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 1 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 1 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 1 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |