Submission #717100

#TimeUsernameProblemLanguageResultExecution timeMemory
717100LittleCube자매 도시 (APIO20_swap)C++14
0 / 100
503 ms46696 KiB
#include "swap.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> #define pii pair<int, int> #define F first #define S second using namespace std; namespace { int N, M, t, pre[100000][20], out[100000][20], dsu[100000], rk[100000], jump[100000][20]; pii io[100000]; vector<pair<int, pii>> edge; vector<pii> E[100000]; int find(int k) { return dsu[k] == k ? k : dsu[k] = find(dsu[k]); } void merge(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (rk[x] < rk[y]) { merge(y, x); return; } dsu[y] = x; rk[x] += rk[y]; } void dfs(int u) { io[u].F = ++t; for (auto [v, w] : E[u]) if (v != pre[u][0]) { pre[v][0] = u; jump[v][0] = w; dfs(v); } io[u].S = t; } bool isChild(int r, int c) { return io[r].F <= io[c].F && io[c].S <= io[r].S; } } void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) { ::N = N, ::M = M; for (int i = 0; i < N; i++) out[i][0] = 2e9, dsu[i] = i, rk[i] = 1; for (int i = 0; i < M; i++) edge.emplace_back(make_pair(W[i], pii(U[i], V[i]))); sort(edge.begin(), edge.end()); for (auto [w, p] : edge) { auto [u, v] = p; if (find(u) == find(v)) out[u][0] = min(out[u][0], w), out[v][0] = min(out[v][0], w); else { merge(u, v); E[u].emplace_back(pii(v, w)); E[v].emplace_back(pii(u, w)); } } dfs(0); for (int p = 0; p < 19; p++) for (int i = 0; i < N; i++) { pre[i][p + 1] = pre[pre[i][p]][p]; jump[i][p + 1] = max(jump[i][p], jump[pre[i][p]][p]); out[i][p + 1] = min(out[i][p], out[pre[i][p]][p]); } } int getMinimumFuelCapacity(int X, int Y) { int lca = X, path = 0, alt = 2e9; for (int p = 19; p >= 0; p--) if (!isChild(pre[lca][p], Y)) lca = pre[lca][p]; if (!isChild(lca, Y)) lca = pre[lca][0]; alt = out[lca][0]; for (int p = 19; p >= 0; p--) if (!isChild(pre[X][p], lca)) { path = max(path, jump[X][p]); alt = min(alt, out[X][p]); X = pre[X][p]; } if (!isChild(X, lca)) { path = max(path, jump[X][0]); alt = min(alt, out[X][0]); X = pre[X][0]; } for (int p = 19; p >= 0; p--) if (!isChild(pre[Y][p], lca)) { path = max(path, jump[Y][p]); alt = min(alt, out[Y][p]); Y = pre[Y][p]; } if (!isChild(Y, lca)) { path = max(path, jump[Y][0]); alt = min(alt, out[Y][0]); Y = pre[Y][0]; } int ans = max(path, alt); return (ans > 1e9 ? -1 : ans); }

Compilation message (stderr)

swap.cpp: In function 'void {anonymous}::dfs(int)':
swap.cpp:40:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |         for (auto [v, w] : E[u])
      |                   ^
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:64:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |     for (auto [w, p] : edge)
      |               ^
swap.cpp:66:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |         auto [u, v] = p;
      |              ^
#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...