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;
using ll = long long;
#define sz(x) ((int)x.size())
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int N = 0;
int cc = 0, k = 0;
int p[2000];
bool arc[2000][2000];
int find(int u) {
return p[u] == u ? u : (p[u] = find(p[u]));
}
void merge(int u, int v) {
if(find(u) == find(v)) return;
--cc;
memset(arc, false, sizeof(arc));
p[find(u)] = find(v);
}
void initialize(int n) {
N = n;
cc = n;
k = 0;
for(int i = 0; i < n; ++i) p[i] = i;
}
int hasEdge(int u, int v) {
++k;
arc[u][v] = arc[v][u] = 1;
if(k == (N * (N-1)) / 2) return 1;
if(find(u) == find(v)) return 1;
bool ok = 1;
for(int i = 0; i < N; ++i) if(find(i) == find(v)) {
if(!arc[i][u]) {
ok = 0;
break;
}
}
if(ok) merge(u, v);
return ok;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |