Submission #755373

#TimeUsernameProblemLanguageResultExecution timeMemory
755373AngusRitossaGame (IOI14_game)C++14
100 / 100
453 ms25164 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int am[1510][1510];
struct UF
{
    int rep[1510];
    void init()
    {
        for (int i = 0; i < n; i++) rep[i] = i;
    }
    int findrep(int a)
    {
        if (rep[a] == a) return a;
        return rep[a] = findrep(rep[a]);
    }
    void merge(int a, int b)
    {
        a = findrep(a);
        b = findrep(b);
        rep[b] = a;
        for (int i = 0; i < n; i++)
        {
            am[a][i] += am[b][i];
            am[i][a] += am[b][i];
        }
    }
};
UF uf;
void initialize(int N) {
    n = N;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++) am[i][j] = 1;
    }
    uf.init();
}

int hasEdge(int u, int v) {
    int a = uf.findrep(u);
    int b = uf.findrep(v);
    if (a == b) { return 0; }
    if (am[a][b] > 1)
    {
        am[a][b]--;
        am[b][a]--;
        return 0;
    }
    uf.merge(u, v);
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...