제출 #216715

#제출 시각아이디문제언어결과실행 시간메모리
216715DS007게임 (IOI14_game)C++14
15 / 100
6 ms512 KiB
#include <bits/stdc++.h> using namespace std; class DSU { int *par, *val; int n, count; public: DSU(int n) { this->n = n; count = 0; par = new int[n]; val = new int[n]; iota(par, par + n, 0); fill(val, val + n, n - 1); } int find(int v) { if (v == par[v]) return v; else return par[v] = find(par[v]); } int merge(int a, int b) { int pa = find(a), pb = find(b); if (pa == pb) return 0; par[pa] = pb; val[pb] += val[pa] - 2; return 1; } int get(int v) { return val[find(v)]; } int update(int u, int v) { val[find(u)]--; val[find(v)]--; count++; return 0; } bool check() { return count < (n - 1) * (n - 2) / 2; } }; DSU *dsu; void initialize(int n) { dsu = new DSU(n); } int hasEdge(int u, int v) { int pu = dsu->find(u), pv = dsu->find(v); assert(pu != pv); if (dsu->get(pu) != 1 && dsu->get(pv) != 1 && dsu->check()) return dsu->update(pu, pv); else return dsu->merge(pu, pv); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...