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 x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
struct Dsu {
int n;
vi par, sz;
Dsu() {}
Dsu(int n): n(n) {
par.resize(n), sz.resize(n, 1);
iota(all(par), 0);
}
int Find(int i) {
return par[i] == i ? i : par[i] = Find(par[i]);
}
void Union(int a, int b) {
int pa = Find(a), pb = Find(b);
if (pa == pb) return;
if (sz[pa] < sz[pb]) swap(pa, pb);
par[pb] = pa;
sz[pa] += sz[pb];
}
};
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 hasEdge(int u, int v) {
if (u > v) swap(u, v);
Dsu dsu(n);
for (auto [a, b] : edges) {
if (a != u || b != v) {
dsu.Union(a, b);
}
}
if (dsu.sz[dsu.Find(0)] != n) return 1;
edges.erase(edges.find({u, v}));
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... |