structEdge { int to, next; } e[maxn * 2]; int c1, head[maxn]; inlinevoidadd_edge(int u, int v){ e[c1].to = v; e[c1].next = head[u]; head[u] = c1++; }
vector<int> a[maxn]; int ans[maxn], bl[maxn], cnt; voiddfs(int u, int fa){ for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].to; if (v == fa) continue; dfs(v, u); for (auto t : a[v]) a[u].push_back(t); if (a[u].size() >= B) { ans[++cnt] = u; for (auto t : a[u]) bl[t] = cnt; a[u].clear(); } } a[u].push_back(u); }
intmain(){ fill(head, head + maxn, -1); ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> B; for (int i = 1; i < n; ++i) { int x, y; cin >> x >> y; add_edge(x, y); add_edge(y, x); } dfs(1, 0); if (!cnt) ans[++cnt] = 1; cout << cnt << "\n"; for (auto u : a[1]) bl[u] = cnt; for (int i = 1; i <= n; ++i) cout << bl[i] << " \n"[i == n]; for (int i = 1; i <= cnt; ++i) cout << ans[i] << " \n"[i == cnt]; return0; }