제출 #1059019

#제출 시각아이디문제언어결과실행 시간메모리
1059019oscarsierra12게임 (IOI14_game)C++14
0 / 100
0 ms2396 KiB
#include "game.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1510;

int fat[N], sz[N];
int nedges[N][N];
int nn = 0;

void ini(int n) {
    for (int i = 0; i < n; ++i) fat[i] = i, sz[i] = 1;
}

int fnd (int x) {
    if (x == fat[x]) return x;
    return fat[x] = fnd(fat[x]);
}

void uni (int x, int y) { 
    int fx = fnd(x), fy = fnd(y);
    fat[fx] = fy;
    sz[fy] += sz[fx];

    for (int z = 0; z < nn; ++z) { 
        nedges[fy][z] += nedges[fx][z];
        nedges[z][fy] += nedges[z][fx];
    }
}

void initialize(int n) {
    nn = n;
    ini(n);
}

int hasEdge(int u, int v) {
    if (nedges[fnd(u)][fnd(v)] == sz[fnd(u)] * sz[fnd(v)] - 1) { 
        uni(u, v);
        return 1;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...