제출 #656357

#제출 시각아이디문제언어결과실행 시간메모리
656357Ronin13게임 (IOI14_game)C++14
0 / 100
1 ms340 KiB
#include "game.h"
#include <bits/stdc++.h>
#define ll long long
#define f first
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
#define s second
using namespace std;

int n;
vector <int> sz(1501);
vector <int> p(1501);
int cnt[1501][1501];

void make_set(int v){
    sz[v] = 1;
    p[v] = v;
    for(int i = 1; i <= n; i++){
        cnt[v][i] = 1;
    }
}

int find_set(int v){
    return p[v] == v ? v : p[v] = find_set(p[v]);
}

int union_sets(int a,int b){
    a = find_set(a);
    b = find_set(b);
    if(a == b) return 0;
    cnt[a][b]--;
    if(!cnt[a][b]){
        if(sz[a] < sz[b]) swap(a, b);
        for(int i = 1; i <= n; i++){
            cnt[i][a] += cnt[i][b];
            cnt[a][i] += cnt[b][i];
        }
        return 1;
    }
    return 0;
}

void initialize(int N) {
    n = N;
    for(int i = 1; i <= n; i++) make_set(i);
}

int hasEdge(int u, int v) {
    u++;
    v++;
    return union_sets(u, v);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...