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>
#define fi first
#define se second
using namespace std;
int n;
vector<int> parent;
vector<vector<int>> edges;
int ufind(int u) {
if (parent[u] == u) return u;
return parent[u] = ufind(parent[u]);
}
void ujoin(int u, int v) {
u = ufind(u);
v = ufind(v);
parent[v] = u;
for (int i = 0; i < n; ++i) {
if (i == u || i == v) continue;
edges[u][i] += edges[v][i];
edges[i][u] = edges[u][i];
}
}
void initialize(int N) {
n = N;
edges = vector<vector<int>>(n, vector<int>(n, 1));
parent = vector<int>(n);
for (int i = 0; i < n; ++i) {
parent[i] = i;
edges[i][i] = 0;
}
}
int hasEdge(int u, int v) {
u = ufind(u), v = ufind(v);
if (u != v) {
if (edges[u][v] == 1) {
ujoin(u, v);
return 1;
}
}
edges[u][v]--;
edges[v][u]--;
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... |