# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476360 | Lam_lai_cuoc_doi | Split the Attractions (IOI19_split) | C++17 | 0 ms | 0 KiB |
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;
using ld = long double;
using ull = unsigned long long;
template <class T>
void read(T &x)
{
x = 0;
register int c;
while ((c = getchar()) && (c > '9' || c < '0'))
;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
}
constexpr bool typetest = 1;
constexpr int N = 2e5 + 5;
constexpr int Inf = 1e9 + 7;
vector<pair<int, int>> adj[N];
bool inused[N];
int cnt[N];
pair<int, int> a[3];
void dfs(int v, int p = 0)
{
cnt[v] = 1;
for (auto i : adj[v])
if (i.first != p)
{
dfs(i.first, v);
cnt[v] += cnt[i.first];
}
}
vector<int> find_split(int n, int A, int B, int C, vector<int> p, vector<int> q)
{
int m = p.size();
vector<int> ans(n, 0);
if (m == n - 1)
{
a[0] = make_pair(A, 1);
a[1] = make_pair(B, 2);
a[2] = make_pair(C, 3);
sort(a, a + 3);
for (int i = 0; i < m; ++i)
{
inused[i] = 1;
adj[p[i]].emplace_back(q[i], i);
adj[q[i]].emplace_back(p[i], i);
}
dfs(0);
int cnt1(0);
function<void(int, int, pair<int, int>)> Colored = [&](int v, int p, pair<int, int> a)
{
++cnt1;
ans[v] = a.second;
if (cnt1 == a.first)
return;
for (auto i : adj[v])
if (inused[i.second] && i.first != p)
{
Colored(i.first, v, a);
if (cnt1 == a.first)
return;
}
};
for (int i = 0; i < n; ++i)
for (auto j : adj[i])
if (cnt[j.first] < cnt[i])
{
if (cnt[j.first] >= a[0].first && (n - cnt[j.first]) >= a[1].first)
{
inused[j.second] = 0;
cnt1 = 0;
Colored(j.first, -1, a[0]);
cnt1 = 0;
Colored(i, -1, a[1]);
}
else if (cnt[j.first] >= a[1].first && (n - cnt[j.first]) >= a[0].first)
{
inused[j.second] = 0;
cnt1 = 0;
Colored(j.first, -1, a[1]);
cnt1 = 0;
Colored(i, -1, a[0]);
}
}
for (auto &i : ans)
if (i == 0)
i = a[2].second;
}
return ans;
}
void Read()
{
}
void Solve()
{
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
//cout << "Case #" << _ << ": ";
Read();
Solve();
}
//cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}