제출 #947702

#제출 시각아이디문제언어결과실행 시간메모리
947702RoupiqGame (IOI14_game)C++17
100 / 100
273 ms17768 KiB
#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
#define len(x) (int)x.size()

vi p;
vector<vi> s;

int Find(int v)
{
    if (p[v] == v)
        return v;
    return p[v] = Find(p[v]);
}

void Union(int u, int v)
{
    u = Find(u), v = Find(v);
    if (u == v)
        return;

    for (int i = 0; i < len(p); i++)
        s[i][u] += s[i][v],
            s[u][i] += s[v][i];
    p[v] = u;
}

void initialize(int n)
{
    p.assign(n, 0);
    s.assign(n, vi(n));
    for (int i = 0; i < n; i++)
        p[i] = i;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            s[i][j] = 1;
}

int hasEdge(int u, int v)
{
    u = Find(u), v = Find(v);
    s[u][v]--, s[v][u]--;
    if (!s[u][v])
    {
        Union(u, v);
        return 1;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...