제출 #436760

#제출 시각아이디문제언어결과실행 시간메모리
436760Tangent게임 (IOI14_game)C++17
42 / 100
1094 ms12672 KiB
#include "game.h" #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vii; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vii> vvii; typedef vector<vll> vvll; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; #define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++) #define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--) #define rep(i, n) ffor(i, 0, n) #define forin(x, a) for (auto &x: a) #define all(a) a.begin(), a.end() int n; vii parent; vector<set<int>> adj; int queries; void initialize(int N) { queries = 0; n = N; parent.assign(n, -1); adj.assign(n, {}); rep(i, n - 1) { ffor(j, i + 1, n) { adj[i].emplace(j); adj[j].emplace(i); } } } int root(int x) { if (parent[x] < 0) return x; return parent[x] = root(parent[x]); } int hasEdge(int u, int v) { if (root(u) == root(v)) { return 1; } adj[u].erase(v); vector<bool> vis(n); int cnt = 1; vis[u] = true; deque<int> q = {u}; while (!q.empty()) { int uu = q.front(); q.pop_front(); forin(vv, adj[uu]) { if (!vis[vv]) { vis[vv] = true; cnt++; q.emplace_back(vv); } } } if (cnt == n) { adj[v].erase(u); return 0; } else { adj[u].emplace(v); int ru = root(u), rv = root(v); if (parent[ru] < parent[rv]) { swap(ru, rv); } parent[rv] += parent[ru]; parent[ru] = rv; return 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...