Submission #372482

#TimeUsernameProblemLanguageResultExecution timeMemory
372482idk321Game (IOI14_game)C++11
100 / 100
511 ms25344 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; const int N = 1500; int sz[N]; int p[N]; int eBetween[N][N]; int n; int getRoot(int node) { if (p[node] == node) return node; p[node] = getRoot(p[node]); return p[node]; } void initialize(int n1) { n = n1; for (int i = 0; i < n; i++) { p[i] = i; sz[i] = 1; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { eBetween[i][j] = 1; eBetween[j][i] = 1; } } } int hasEdge(int u, int v) { u = getRoot(u); v = getRoot(v); if (eBetween[u][v] == 1) { if (sz[u] < sz[v]) { swap(u, v); } sz[u] += sz[v]; for (int i = 0; i < n; i++) { int num = eBetween[v][i]; eBetween[u][i] += num; eBetween[i][u] += num; } p[v] = u; return 1; } else { eBetween[u][v]--; eBetween[v][u]--; return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...