传送门
树分块(树上莫队前置技能)
贪心判断当前结点大小,大于B暴力分出一块,省会当前结点。
这样块的大小都满足大于B小于2B
到最后一定只剩下一块大小小于B的节点,暴力加入最后一个块即可.
var
a,b,c,ca,st,si,be:array [0..3005] of longint;
n,bb,x,y,i,tot:longint;
procedure ins(x,y:longint);
begin inc(tot); a[tot]:=y; b[tot]:=c[x]; c[x]:=tot; end;
procedure cap(x,fa:longint);
var p:longint;
begin
inc(st[0]); st[st[0]]:=x; p:=c[x];
while p<>0 do begin
if a[p]<>fa then begin
cap(a[p],x);
if si[x]+si[a[p]]>=bb then begin
si[x]:=0; inc(ca[0]); ca[ca[0]]:=x;
while st[st[0]]<>x do begin be[st[st[0]]]:=ca[0]; dec(st[0]); end;
end
else si[x]:=si[x]+si[a[p]];
end;
p:=b[p];
end;
inc(si[x]);
end;
procedure paint(x,fa,cc:longint);
var p:longint;
begin
if be[x]<>0 then cc:=be[x] else be[x]:=cc;
p:=c[x];
while (p<>0) do begin
if a[p]<>fa then paint(a[p],x,cc);
p:=b[p];
end;
end;
begin
read(n,bb);
if n<bb then begin write(0); exit; end;
for i:=1 to n-1 do begin read(x,y); ins(x,y); ins(y,x); end;
cap(1,0);
if ca[0]=0 then inc(ca[0]);
paint(1,0,ca[0]);
writeln(ca[0]);
for i:=1 to n do write(be[i],' ');
writeln;
for i:=1 to ca[0] do write(ca[i],' ');
end.