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 "game.h"
#include <tuple>
#include <algorithm>
using namespace std;
int uf[1506], cnt[1506][1506], n;
int _find(int x) {
if (uf[x] == -1) return x;
return uf[x] = _find(uf[x]);
}
void initialize(int N) {
n = N;
for (int i = 0; i < n; i++) {
uf[i] = -1;
for (int j = i + 1; j < n; j++) cnt[i][j] = 1;
}
}
int hasEdge(int u, int v) {
u = _find(u), v = _find(v);
if (u == v) return 0;
tie(u, v) = make_pair(min(u, v), max(u, v));
if (cnt[u][v] > 1) return cnt[u][v]--, 0;
for (int i = 0; i < n; i++) if (_find(i) == i && _find(i) != u && _find(i) != v) {
auto [ a, b ] = make_pair(min(u, i), max(u, i));
auto [ c, d ] = make_pair(min(v, i), max(v, i));
cnt[a][b] += cnt[c][d];
}
uf[v] = u;
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |