제출 #380865

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

using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
const int N=2e3+10;
int n, root[N], mark[N][N],cnt[N][N];
vi S[N];

void merg(int u, int v)
{
    if (S[u].size() < S[v].size()) swap(u, v);
    for (int x : S[v])
    {
        for (int i = 0; i < n; ++i)
            if (i!=x && !mark[i][x])
            {
                int ri = root[i];
                if (ri < u) cnt[ri][u]++;
                else cnt[u][ri]++;
            }
        root[x] = u;
        S[u].eb(x);
    }
    S[v].clear();
}

void initialize(int x)
{
    n = x;
    for (int i = 0; i < n; ++i) root[i] = i, S[i].clear(), S[i].eb(i);
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j) mark[i][j] = 0, cnt[i][j] = 1;
}

int hasEdge(int u, int v)
{
    if (u > v) swap(u, v);
    mark[u][v] = 1;
    int ru = root[u];
    int rv = root[v];
    if (ru > rv) swap(ru, rv);
    cnt[ru][rv]--;
    if (cnt[ru][rv] > 0) return 0;
    merg(ru, rv);
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...