var
n,k,l,o,p,d,no:longint;
i,j,c,z,r,path:array[1..100000] of longint;
BEGIN
{vhod---}
read(n);
readln(k);
for l:=1 to (n-1) do
begin
 read(i[l]);
 read(j[l]);
 readln(c[l]);
end;
for l:=1 to k do
readln(z[l]);
{-------}
for l:=1 to n do
 begin
  for o:=1 to k do
   begin
    for p:=1 to n do
     begin
      path[o]:=path[o-1]+
     end;
     for n:=1 to k do
     for l:=1 to k do
       begin
        if (path[l]>path[l+1])  then begin
        d:=path[l+1];
        path[l+1]:=path[l];
        path[l]:=d;                   end;
       end;
       no:=
   end;
   write(no);
   writeln(path[1]);
 end;
END.
