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 vi = vector<int>;
#define len(x) (int)x.size()
vi p;
vector<vi> s;
int Find(int v)
{
if (p[v] == v)
return v;
return p[v] = Find(p[v]);
}
void Union(int u, int v)
{
u = Find(u), v = Find(v);
if (u == v)
return;
for (int i = 0; i < len(p); i++)
s[i][u] += s[i][v],
s[u][i] += s[v][i];
p[v] = u;
}
void initialize(int n)
{
p.assign(n, 0);
s.assign(n, vi(n));
for (int i = 0; i < n; i++)
p[i] = i;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
s[i][j] = 1;
}
int hasEdge(int u, int v)
{
u = Find(u), v = Find(v);
s[u][v]--, s[v][u]--;
if (!s[u][v])
{
Union(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... |