type
   PList = ^TList;
   TList = record
      next : pList;
      j : longint;
      w : longint;
   end;
var
   a : array[1..100000] of PList;
   b : array[1..100000] of record
      z,w : longint;
   end;
   v : array[1..100000] of boolean;
   n,k,i : longint;
procedure Add(i,j,w : longint);
var
   p0 : PList;
begin
   p0:=a[i];
   new(a[i]);
   a[i]^.j:=j;
   a[i]^.w:=w;
   a[i]^.next:=p0;
   p0:=a[j];
   new(a[j]);
   a[j]^.j:=i;
   a[j]^.w:=w;
   a[j]^.next:=p0;
end;
procedure wave(q,w : longint);
var
   p : Plist;
begin
   v[q]:=true;
   p:=a[q];
   while p<>nil do
      begin
         if (b[p^.j].z=0)or(w+p^.w<b[p^.j].w) then
            begin
               b[p^.j].z:=i;
               b[p^.j].w:=w+p^.w;
               wave(p^.j,b[p^.j].w);
            end;
         if not v[p^.j] then wave(p^.j,w+p^.w);
         p:=p^.next;
      end;
end;
procedure ReadFile;
var
   q,p,w : longint;
begin
   readln(n,k);
   for i:=1 to n-1 do
      begin
         readln(q,p,w);
         Add(q,p,w);
      end;
   for i:=1 to k do
      begin
         readln(q);
         w:=b[q].w;
         p:=b[q].z;
         b[q].w:=0;
         Wave(q,0);
         b[q].w:=w;
         b[q].z:=p;
         if i<>k then fillchar(v,n,false);
      end;
end;
procedure writefile;
begin
   for i:=1 to n do
      writeln(b[i].z,' ',b[i].w);
end;
begin
   readfile;
   writefile;
end.