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>
using namespace std;
#define MAXN 1500
int fathers[MAXN];
int connections[MAXN][MAXN];
void initialize (int n) {
for (int x = 0; x < n; x++) {
fathers[x] = x;
for (int y = 0; y < n; y++) connections[x][y] = 1;
connections[x][x] = 0;
}
}
int find (int n) {return fathers[n] == n ? n : fathers[n] = find(fathers[n]);}
void merge (int u, int v) {
fathers[u] = v;
for (int x = 0; x < MAXN; x++) {
connections[v][x] += connections[u][x];
connections[x][v] += connections[u][x];
}
}
int hasEdge (int u, int v) {
u = find (u), v = find(v);
if (v < u) swap(v,u);
if (connections[u][v] == 1 && connections[v][u] == 1) {
merge(u,v);
return 1;
}
connections[u][v]--;
connections[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... |