Submission #800719

#TimeUsernameProblemLanguageResultExecution timeMemory
800719BERNARB01Game (IOI14_game)C++17
0 / 100
20 ms32212 KiB
#include <bits/stdc++.h> #include "game.h" using namespace std; #ifdef B01 #include "../deb.h" #else #define deb(...) #endif struct dsu { vector<int> p; dsu() {} dsu(int n) { p.assign(n, -1); } inline int get(int x) { return (p[x] < 0 ? x : (p[x] = get(p[x]))); } inline void unite(int x, int y) { x = get(x); y = get(y); if (p[x] < p[y]) { swap(x, y); } p[y] += p[x]; p[x] = y; } }; const int N = 2003; int n; dsu d; int g[N][N]; void initialize(int n_) { d = dsu(n); memset(g, -1, sizeof g); } int hasEdge(int u, int v) { if (g[u][v] != -1) { return g[u][v]; } int pu = d.get(u); int pv = d.get(v); if (pu == pv) { g[u][v] = g[v][u] = 0; return 0; } vector<int> l, r; for (int i = 0; i < n; i++) { int pi = d.get(i); if (pi == pu) { l.push_back(i); } if (pi == pv) { r.push_back(i); } } bool bl = true; for (int x : l) { for (int y : r) { if (g[x][y] != 0) { bl = false; } } } if (bl) { g[u][v] = g[v][u] = 1; return 1; } g[u][v] = g[v][u] = 0; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...