Submission #1084077

#TimeUsernameProblemLanguageResultExecution timeMemory
1084077KasymKGame (IOI14_game)C++17
0 / 100
1 ms348 KiB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 2e3+5;
int num_comp, cnt;
bool start = false;
int rep[N], sz[N];

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

void merge(int a, int b){
    int x = find(a), y = find(b);
    assert(x != y); // ikisi bir componentda dal
    if(sz[y] > sz[x])
        swap(x, y);
    sz[x] += sz[y];
    rep[y] = x;
}

void initialize(int n){
    num_comp = n;
    for(int i = 1; i <= n; ++i)
        rep[i] = i, sz[i] = 1;
    return;
}

int hasEdge(int u, int v){
    u++, v++;
    if(find(u) == find(v))
        return 1; // componentlan sany uytganok
    // diymek ikisi bir componentda dal
    if(start)
        return 0;
    merge(u, v); // componentlardan bir san ayyrylyar
    num_comp--;
    if(num_comp == 2)
        start = true;
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...