Submission #835738

#TimeUsernameProblemLanguageResultExecution timeMemory
835738Lobo게임 (IOI14_game)C++17
0 / 100
107 ms262144 KiB
#include "game.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

const int maxn = 1510;

int made[maxn][maxn], ds[maxn];
vector<int> dsv[maxn];

int find(int v) {
    if(v == find(v)) return v;
    return ds[v] = find(ds[v]);
}

void join(int u, int v) {
    if(dsv[u].size() < dsv[v].size()) swap(u,v);
    for(auto x : dsv[v]) dsv[u].pb(x);
    ds[v] = u;
}


void initialize(int n) {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            made[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++) {
        ds[i] = i;
        dsv[i].pb(i);
    }
}


int hasEdge(int u, int v) {
    made[u][v] = 1;
    u = find(u);
    v = find(v);
    assert(u != v);

    bool ok = true;
    for(auto x : dsv[u]) {
        for(auto y : dsv[v]) {
            if(made[x][y] == 0) ok = false;
        }
    }
    if(ok) {
        join(u,v);
        return 1;
    }
    else {
        return 0;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...