#include<iostream> #include<cstdio> #include<algorithm> using namespace std; #define N 3000 int n,m,cnt,tot,top,x,y,belong[N],stk[N],ans[N],head[N]; struct edge{int v,nxt;}e[N]; void add(int x,int y){e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;} void dfs(int u,int fa){ int now=top; for (int i=head[u];i;i=e[i].nxt){ int v=e[i].v; if (v==fa) continue; dfs(v,u); if (top-now>=m){ans[++cnt]=u; for (;top-now;top--) belong[stk[top]]=cnt;} } stk[++top]=u; } int main(){ scanf("%d%d",&n,&m); if (n<m){puts("0"); return 0;} for (int i=1;i<n;i++){scanf("%d%d",&x,&y); add(x,y); add(y,x);} dfs(1,0); for (;top;top--) belong[stk[top]]=cnt; printf("%d\n",cnt); for (int i=1;i<=n;i++) printf("%d ",belong[i]); puts(""); for (int i=1;i<=cnt;i++) printf("%d ",ans[i]); puts(""); return 0; }
|