# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1256779 | rhm_gan | Split the Attractions (IOI19_split) | C++20 | 0 ms | 0 KiB |
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
vector<int> g[N];
vector<int> res;
bool vis[N];
int A, B, C;
vector<int> path;
void dfs(int u, int c) {
int mx = N;
if (c == 1) mx = A;
if (c == 2) mx = B;
if (c == 3) mx = C;
if (path.size() == mx) {
return;
}
vis[u] = true;
path.push_back(u);
for (auto v : g[u]) {
if (!vis[v]) {
dfs(v, c);
}
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
if (a > c) swap(a, c);
if (a > b) swap(a, b);
if (b > c) swap(b, c);
A = a; B = b; C = c;
int m = p.size();
res.resize(n, -1);
for (int i = 0; i < m; i++) {
g[p[i]].push_back(q[i]);
g[q[i]].push_back(p[i]);
}
int u = 0;
for (int i = 0; i < n; i++) {
if (g[i].size() == 1) {
u = i;
break;
}
}
dfs(u, 1);
for (auto u : path) {
res[u] = 1;
}
for (int i = 0; i < n; i++) {
if (!vis[i]) {
path.clear();
dfs(i, 2);
if (path.size() == b) {
for (auto u : path) {
res[u] = 2;
}
for (int i = 0; i < n; i++) {
if (res[i] == -1) {
res[i] = 3;
}
}
return res;
}
}
}
return {};
}
int main() {
int n, m, a, b, c;
assert(5 == scanf("%d%d%d%d%d", &n, &m, &a, &b, &c));
vector<int> p(m), q(m);
for (int i=0; i<m; i++)
assert(2 == scanf("%d%d", &p[i], &q[i]));
// fclose(stdin);
vector<int> result = find_split(n, a, b, c, p, q);
for (int i=0; i<(int)result.size(); i++)
printf("%s%d", ((i>0)?" ":""), result[i]);
printf("\n");
// fclose(stdout);
return 0;
}