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 <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <tuple>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
const ll SZ = 2000;
ll dsu[SZ], add[SZ][SZ], nn;
int par(int v) {
if (dsu[v] == v) return dsu[v];
return dsu[v] = par(dsu[v]);
}
void uni(int v, int u) {
v = par(v);
u = par(u);
if (u != v) dsu[u] = v;
}
void initialize(int n) {
for (int i = 0; i < n; i++) dsu[i] = i;
nn = n;
}
int hasEdge(int u, int v) {
if (u > v) swap(u, v);
int n = nn;
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (par(u) == par(i) && par(j) == par(v)) {
if (add[i][j] == 0) cnt++;
}
}
}
if (cnt == 1) {
add[u][v] = 1;
uni(u, v);
return 1;
}
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... |