This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
void initialize(int n);
int hasEdge(int u, int v);
const int N = 1001;
int n, mp[N], par[N];
int root(int x) {
return x == par[x] ? x : par[x] = root(par[x]);
}
void merge(int u, int v) {
u = root(u), v = root(v);
if (u == v) return;
par[v] = u;
}
void initialize(int cnt)
{
n = cnt;
for (int i = 1; i <= cnt; i++)
mp[i] = 0;
for (int i = 1; i <= cnt; i++)
par[i] = i;
}
int hasEdge(int u, int v)
{
if (u > v) {
int tmp = u;
u = v;
v = tmp;
}
if (root(u) == root(v))
return 1;
mp[u]++, mp[v]++;
if (mp[u] == n-1 || mp[v] == n-1) {
merge(u, v);
mp[u] = 0;
mp[v] = 0;
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... |