이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 leaf;
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;
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;
}
int hasEdge(int u, int v)
{
s[u]--;
s[v]--;
if(s[u] == 0 || s[v] == 0)
{
Union(u, v);
if(s[Find(u)] == 1)
leaf = Find(u);
else
leaf = false;
return 1;
}
if(leaf == false && s[u] == 1)
{
Union(u, v);
if(s[Find(u)] == 1)
leaf = Find(u);
return 1;
}
if(leaf == false && s[v] == 1)
{
Union(u, v);
if(s[Find(u)] == 1)
leaf = Find(u);
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... |