Submission #476968

#TimeUsernameProblemLanguageResultExecution timeMemory
476968JovanBGame (IOI14_game)C++17
100 / 100
456 ms25176 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; const int N = 1500; struct DSU{ int n; int par[N+5]; int edg[N+5][N+5]; int outs[N+5]; int sz[N+5]; void init(int _n){ n = _n; for(int i=1; i<=n; i++){ par[i] = i; sz[i] = 1; outs[i] = 0; for(int j=1; j<=n; j++){ edg[i][j] = 0; } } } int root(int x){ return (par[x] == x ? x : par[x] = root(par[x])); } bool povezi(int a, int b){ a = root(a); b = root(b); if(a == b) return 1; if(sz[a] < sz[b]) swap(a, b); if(edg[a][b] != sz[a]*sz[b] - 1){ outs[a]++, outs[b]++; edg[a][b]++, edg[b][a]++; return 0; } outs[a] -= edg[a][b]; outs[b] -= edg[a][b]; for(int i=1; i<=n; i++) edg[a][i] += edg[b][i], edg[i][a] += edg[i][b]; outs[a] += outs[b]; sz[a] += sz[b]; par[b] = a; return 1; } } dsu; void initialize(int _n) { dsu.init(_n); } int hasEdge(int u, int v) { return dsu.povezi(u + 1, v + 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...