Submission #889140

#TimeUsernameProblemLanguageResultExecution timeMemory
889140shezittGame (IOI14_game)C++14
15 / 100
1 ms500 KiB
#include "game.h"
#include <bits/stdc++.h>
 
// Subtask 1 n = 4
 
using namespace std;
 
const int N = 1505;
int cont[N];
int pa[N];
int neg = 0;
int n, r;

int find(int x){
    if(x == pa[x]) return x;
    return pa[x] = find(pa[x]);
}

void join(int a, int b){
    a = find(a), b = find(b);
    pa[b] = a;
    return;
}

void initialize(int nn) {
    memset(cont, 0, sizeof cont);
    neg = 0;
    n = nn;
    r = n * (n - 1) / 2;
    for(int i=0; i<n; ++i){
        pa[i] = i;
    }
    return;
}
 
int hasEdge(int u, int v) {
    // if(find(u) == u && find(v) == v){
    //     // could be positive
    //     join(u, v);
    //     return 1;
    // }
    if(cont[u] == n-2 or cont[v] == n-2){
        // must be positive
        join(u, v);
        return 1;
    }
    if(neg == r - n + 1){
        // must be positive
        join(u, v);
        return 1;
    }
    cont[u]++;
    cont[v]++;
    neg++;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...