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>
#define lb lower_bound
#define LINE "------------\n"
using namespace std;
using PII = pair <int, int>;
const int N = 1500;
// bool path[N][N];
set <PII> edges;
int n;
void initialize(int _n) {
n = _n;
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++) {
edges.insert({i, j});
}
}
int par[N];
int find(int a) {
return par[a] = (par[a] == a ? a : find(par[a]));
}
bool merge(int a, int b) {
a = find(a);
b = find(b);
if (a == b) return 0;
par[b] = a;
return 1;
}
int hasEdge(int u, int v) {
if (u > v) swap(u, v);
edges.erase({u, v});
int disjoint = n;
iota(par, par+n, 0);
for (auto [a, b] : edges) {
if (disjoint == 1) break;
// cout << a << " " << b << " "
disjoint -= merge(a, b);
}
if (disjoint != 1) edges.insert({u, v});
return disjoint != 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... |