Submission #895469

#TimeUsernameProblemLanguageResultExecution timeMemory
895469ByeWorldGame (IOI14_game)C++14
100 / 100
290 ms26036 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1510; int n; int par[MAXN], siz[MAXN], no[MAXN][MAXN]; int f(int x){ if(par[x]==x) return x; return par[x] = f(par[x]); } bool con(int x, int y){ x = f(x); y = f(y); return x==y; } void mer(int x, int y){ x = f(x); y = f(y); if(con(x, y)) return; if(siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; for(int i=1; i<=n; i++){ int num = no[i][y]; if(i > y) num = no[y][i]; if(i < x) no[i][x] += num; else no[x][i] += num; } } void initialize(int N) { n = N; for(int i=1; i<=n; i++){ par[i] = i; siz[i] = 1; } } int hasEdge(int u, int v) { u++; v++; if(con(u, v)) return 0; // udh connected u = f(u); v = f(v); if(u > v) swap(u, v); if(no[u][v] == siz[u] * siz[v] - 1){ mer(u, v); // tinggal 1 doang return 1; } // masi lebih dari 1 no[u][v]++; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...