# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1193425 | dong_gas | Split the Attractions (IOI19_split) | C++20 | 0 ms | 0 KiB |
{
vector<pair<int, int>> t = {{_a, 1}, {_b, 2}, {_c, 3}};
sort(all(t));
a = t[0].first, b = t[1].first, c = t[2].first, n = _n, m = p.size();
ds = disjoint_set(n);
vector<pair<int, int>> edges;
for (int i = 0; i < m; i++) {
if (ds.Union(p[i], q[i])) tree[p[i]].push_back(q[i]), tree[q[i]].push_back(p[i]);
else edges.push_back({p[i], q[i]});
adj[p[i]].push_back(q[i]), adj[q[i]].push_back(p[i]);
}
dfs(0), B = cent = get_cent(0, -1, n);
visited[cent] = 1;
// for (int i=0;i<n;i++) ds.papa[i] = -1;
// for (int i = 0; i < n; i++) cout << ds.sz[i] << endl;
ds = disjoint_set(n);
for (int v: adj[cent]) grouping(v, cent);
for (int v: adj[cent]) {
if (ds.sz[ds.Find(v)] >= a) A = v;
}
// cout << A << endl;
for (auto& [u, v]: edges) {
if (A != -1) break;
if (u == cent || v == cent) continue;
ds.Union(u, v);
if (ds.sz[ds.Find(u)] >= a) A = ds.Find(u);
}
// cout << cent << ' ' << A << endl << endl;
if (A == -1) return vector<int>(n, 0);
res.resize(n, 3);
go(A); // A랑 같은 ds인 놈들만 탐색
visited[cent] = 0;
gogo(B);
// for (int i = 0; i < n; i++) cout << i << ' ' << res[i] << endl;
for (int i = 0; i < n; i++) res[i] = t[res[i] - 1].second;
return res;
}