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 <bits/stdc++.h>
using namespace std;
vector<int> uf;
int root(int u) { return u == uf[u] ? u : uf[u] = root(uf[u]); }
void merge(int u, int v) { uf[root(u)] = root(v); }
int N;
vector<vector<int>> madj;
void initialize(int __N) {
N = __N;
madj.assign(N, vector<int>(N, -1));
uf.resize(N);
iota(uf.begin(), uf.end(), 0);
}
int hasEdge(int u, int v) {
bool choice = true;
for (int i = 0; i < N; i++) {
if (u != i && v != i && madj[u][i] == -1 && (root(i) == root(v) || root(i) == root(u))) {
choice = false;
}
if (u != i && v != i && madj[v][i] == -1 && (root(i) == root(v) || root(i) == root(u))) {
choice = false;
}
}
madj[u][v] = madj[v][u] = choice;
if (choice) {
merge(u, v);
}
return choice;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |