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"
// ultima problema degeaba pe ziua de azi promit
using namespace std;
struct DSU {
int n;
vector<int> dad, sz;
vector<vector<int>> edges;
DSU(int n_) : n(n_), dad(n, -1), sz(n, 1), edges(n, vector<int>(n)) {}
int Find(int node) {
if (dad[node] == -1) return node;
return dad[node] = Find(dad[node]);
}
bool Union(int x, int y) {
x = Find(x), y = Find(y);
++edges[x][y], ++edges[y][x];
if (sz[x] < sz[y]) swap(x, y);
if (edges[x][y] != sz[x] * sz[y]) {
return false;
}
sz[x] += sz[y];
dad[y] = x;
for (int i = 0; i < n; ++i) {
if (i == x || i == y || dad[i] != -1) continue;
edges[x][i] += edges[y][i];
edges[i][x] += edges[i][y];
}
return true;
}
};
DSU dsu(0);
void initialize(int n) {
dsu = DSU(n);
}
int hasEdge(int u, int v) {
return dsu.Union(u, v);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |