Submission #1067580

#TimeUsernameProblemLanguageResultExecution timeMemory
1067580beaconmcGame (IOI14_game)C++14
42 / 100
217 ms30548 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 


ll paths[1501][1051];
ll N = 0;

ll cmp[1501];

ll find(ll a){
    while (a != cmp[a]){
        cmp[a] = cmp[cmp[a]];
        a = cmp[a];
    }
    return a;
}


void unite(ll a, ll b){
    ll A = find(a);
    ll B = find(b);
    cmp[A] = B;



    FOR(i,0,1051){
        paths[B][i] = paths[A][i] + paths[B][i];
        paths[i][B] = paths[i][A] + paths[i][B];
    }
    // FOR(i,0,1051){
    //     paths[A][i] = 0;
    //     paths[i][A] = 0;
    // }
}

void initialize(int n){
    FOR(i,0,1501) cmp[i] = i;
    FOR(i,0,n+1) FOR(j,0,n+1) paths[i][j] = 1;
}
int hasEdge(int u, int v){
    ll U = find(u);
    ll V = find(v);
    paths[U][V]--;
    paths[V][U]--;



    if (paths[U][V] == 0){
        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...