제출 #1006601

#제출 시각아이디문제언어결과실행 시간메모리
1006601MardonbekhazratovGame (IOI14_game)C++17
0 / 100
1 ms600 KiB
#include "game.h"
#include<bits/stdc++.h>

using namespace std;

int n;
vector<int>p,c,sz;
vector<bool>vis;

int find(int x){
    if(x==p[x]) return x;
    return p[x]=find(p[x]);
}

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

bool unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return 0;
    if(sz[x]<sz[y]) swap(x,y);
    p[y]=x;
    sz[x]+=sz[y];
    return 1;
}

void initialize(int N) {
    n=N;
    p.resize(n);
    iota(p.begin(),p.end(),0);
    sz.assign(n,1);
    c.assign(n,0);
    vis.assign(n,0);
}

int hasEdge(int u, int v) {
    c[u]++;
    c[v]++;
    if((c[u]==n-1 || c[v]==n-1) && !same(u,v)){
        unite(u,v);
        return 1;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...