This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |