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;
#ifdef B01
#include "../deb.h"
#else
#define deb(...)
#endif
struct dsu {
vector<int> p;
dsu() {}
dsu(int n) {
p.assign(n, -1);
}
inline int get(int x) {
return (p[x] < 0 ? x : (p[x] = get(p[x])));
}
inline void unite(int x, int y) {
x = get(x);
y = get(y);
if (p[x] < p[y]) {
swap(x, y);
}
p[y] += p[x];
p[x] = y;
}
};
const int N = 2003;
int n;
dsu d;
int g[N][N];
void initialize(int n_) {
n = n_;
d = dsu(n);
memset(g, -1, sizeof g);
}
int hasEdge(int u, int v) {
if (g[u][v] != -1) {
return g[u][v];
}
int pu = d.get(u);
int pv = d.get(v);
if (pu == pv) {
g[u][v] = g[v][u] = 1;
return 1;
}
vector<int> l, r;
for (int i = 0; i < n; i++) {
if (i == u || i == v) {
continue;
}
int pi = d.get(i);
if (pi == pu) {
l.push_back(i);
}
if (pi == pv) {
r.push_back(i);
}
}
bool bl = true;
for (int x : l) {
for (int y : r) {
if (g[x][y] != 0) {
bl = false;
break;
}
}
if (!bl) {
break;
}
}
if (bl) {
g[u][v] = g[v][u] = 1;
return 1;
}
g[u][v] = g[v][u] = 0;
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... |