Submission #1356298

#TimeUsernameProblemLanguageResultExecution timeMemory
1356298takoshanavaGame (IOI14_game)C++20
0 / 100
0 ms344 KiB
#include "game.h"
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
using namespace std;

const int N = 1505;
int par[N], sz[N], lft[N][N], n;

int get(int a){
    if(a == par[a]) return a;
    return par[a] = get(par[a]);
}

void unite(int a, int b){
    a = get(a), b = get(b);
    if(sz[a] > sz[b]) swap(a, b);
    par[a] =b;
    sz[b] += sz[a];
    for(int i = 0; i < n; i++) lft[b][get(i)] = sz[b];
}

void initialize(int nn) {
    n = nn;
    for(int i = 0; i < n; i++) par[i] = i, sz[i] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            lft[i][j] = 1;
        }
    }
}

int hasEdge(int u, int v) {
    u = get(u), v = get(v);
    if(lft[u][v] == 1 and lft[v][u] == 1){
        unite(u, v);
        return 1;
    }
    lft[u][v]--, lft[v][u]--;
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...