Submission #1230654

#TimeUsernameProblemLanguageResultExecution timeMemory
1230654AMel0nGame (IOI14_game)C++20
100 / 100
355 ms15920 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second

#include "game.h"

int N;
vector<int> par;
vector<vector<int>> q;
int find(int n) {
    if (par[n] == n) return par[n];
    return par[n] = find(par[n]);
}
void merge(int a, int b) {
    par[b] = a;
    FOR(i, N) {
        q[i][a] = q[a][i] += q[b][i];
    }
}

void initialize(int n){
    N = n;
    par.resize(N);
    FOR(i, N) par[i] = i;
    q.resize(N, vector<int>(N, 1));
    FOR(i, N) q[i][i] = 0;
}


int hasEdge(int u, int v){
    u = find(u);
    v = find(v);
    q[u][v]--;
    q[v][u]--;
    if (q[u][v]) return 0;
    merge(u, v);
    return 1; // only answer yes until the last flight between 2 components is asked
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...