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 <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
#define len(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
#define x first
#define y second
vi p, s;
int sajz;
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;
sajz--;
s[u] += s[v];
p[v] = u;
}
void initialize(int n)
{
p.resize(n);
s.resize(n, n - 1);
for (int i = 0; i < n; i++)
p[i] = i;
sajz = n;
}
int hasEdge(int u, int v)
{
u = Find(u);
v = Find(v);
s[u]--;
s[v]--;
// cout << s[u] << " " << s[v] << "\n";
if (sajz > 2 && (s[u] == 1 || s[v] == 1))
{
Union(u, v);
return 1;
}
else if (s[u] == 0 || s[v] == 0)
{
Union(u, v);
return 1;
}
return 0;
}
// int main()
// {
// int n;
// cin >> n;
// initialize(n);
// for (int a, b, i = 0; i < n * (n - 1); i++)
// {
// cin >> a >> b;
// for (int i = 0; i < n; i++)
// {
// }
// }
// }
//
/*
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |