# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
257417 | 2020-08-04T08:56:08 Z | islingr | Amusement Park (JOI17_amusement_park) | C++17 | 0 ms | 0 KB |
#include "Ioi.h" #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (auto i = (a); i < (b); ++i) #define all(x) begin(x), end(x) using ll = long long; namespace { const int N = 1 << 14, B = 60; int nxt[N]; int head(int u) { return nxt[u] != u ? nxt[u] = head(nxt[u]) : u; } bool unite(int u, int v) { u = head(u); v = head(v); if (u == v) return 0; nxt[u] = v; return 1; } vector<int> g[N]; int p[N], in[N], timer = 0; void init(int u) { in[u] = timer; if (++timer == B) timer = 0; for (int v : g[u]) { g[v].erase(find(all(g[v]), u)); p[v] = u; init(v); } } ll U = (1ll << B) - 1, cur = 0, x = 0; bool dfs(int u, ll z) { cur |= 1ll << in[u]; x |= z << in[u]; if (cur == U) return true; for (int v : g[u]) { if (cur & 1ll << in[v]) continue; if (dfs(v, Move(v))) return true; Move(u); } return false; } } ll Ioi(int n, int m, int a[], int b[], int P, int V, int T) { rep(u, 0, n) nxt[u] = u; rep(e, 0, m) { if (unite(a[e], b[e])) { g[a[e]].push_back(b[e]); g[b[e]].push_back(a[e]); } } init(0); while (!dfs(P, V)) V = Move(p[P]), P = p[P]; return x; }