Submission #301655

#TimeUsernameProblemLanguageResultExecution timeMemory
301655kevinsogoGame (IOI14_game)C++17
100 / 100
596 ms15908 KiB
#include <bits/stdc++.h> #include "game.h" using namespace std; vector<vector<int>> counts; vector<int> mins, sz; int n; void initialize(int n) { ::n = n; counts = vector<vector<int>>(n, vector<int>(n)); mins = vector<int>(n); sz = vector<int>(n, 1); iota(mins.begin(), mins.end(), 0); } void merge(int u, int v) { if (u > v) swap(u, v); assert(u < v); sz[u] += sz[v]; for (int i = 0; i < n; i++) { if (mins[i] == v) mins[i] = u; } for (int i = 0; i < n; i++) { counts[i][u] += counts[i][v]; counts[u][i] += counts[v][i]; } } int hasEdge(int u, int v) { u = mins[u], v = mins[v]; counts[u][v]++, counts[v][u]++; if (counts[u][v] == sz[u] * sz[v]) { merge(u, v); return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...