제출 #519082

#제출 시각아이디문제언어결과실행 시간메모리
519082tabrGame (IOI14_game)C++17
42 / 100
1086 ms1324 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

struct dsu {
    vector<int> p;
    vector<int> sz;
    int n;

    dsu(int _n) : n(_n) {
        p = vector<int>(n);
        iota(p.begin(), p.end(), 0);
        sz = vector<int>(n, 1);
    }

    inline int get(int x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = get(p[x]);
        }
    }

    inline bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        p[x] = y;
        sz[y] += sz[x];
        return true;
    }

    inline bool same(int x, int y) {
        return (get(x) == get(y));
    }

    inline int size(int x) {
        return sz[get(x)];
    }
};

int n;
bitset<1500> g[1500];
dsu uf(0);

void initialize(int _n) {
    n = _n;
    uf = dsu(n);
}

int hasEdge(int u, int v) {
    assert(!uf.same(u, v));
    vector<int> a, b;
    for (int i = 0; i < n; i++) {
        if (uf.same(i, u)) {
            a.emplace_back(i);
        } else if (uf.same(i, v)) {
            b.emplace_back(i);
        }
    }
    g[u][v] = g[v][u] = 1;
    bitset<1500> c;
    for (int i : b) {
        c[i] = 1;
    }
    for (int i : a) {
        if ((g[i] & c).count() != b.size()) {
            return 0;
        }
    }
    uf.unite(u, v);
    return 1;
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...