Submission #835309

#TimeUsernameProblemLanguageResultExecution timeMemory
835309_martynasGame (IOI14_game)C++11
100 / 100
275 ms15820 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; using namespace std::chrono; const int mxn = 1505; int n; int par[mxn], sz[mxn]; int cons[mxn][mxn]; bool seen_set[mxn]; vector<int> sets; int find_set(int a) { int temp = par[a] == a ? a : par[a] = find_set(par[a]); return temp; } int join_calls = 0; int inner_loop = 0; void join(int a, int b) { join_calls++; if(sz[b] > sz[a]) swap(a, b); par[b] = a; sz[a] += sz[b]; for(int i : sets) if(i != a) { cons[a][i] += cons[b][i]; cons[i][a] += cons[i][b]; inner_loop++; } sets.erase(find(sets.begin(), sets.end(), b)); } void initialize(int N) { n = N; for(int i = 0; i < n; i++) par[i] = i, sz[i] = 1, sets.push_back(i); } int hasEdge(int u, int v) { // add edge if cons between u and v are equal to sz_u * sz_v - 1 u = find_set(u), v = find_set(v); assert(u != v); if(cons[u][v] == sz[u]*sz[v]-1) { join(u, v); return 1; } else { cons[u][v]++, cons[v][u]++; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...