const
 maxn=7000;
var
 a:array[1..maxn,1..maxn] of longint;
 b:array[1..maxn] of longint;
 min,i,j,k,l,t,n,p:longint;
begin
 readln(n,p);
 for i:=1 to n-1 do begin
  readln(k,l,t);
  a[k,l]:=t;
  a[l,k]:=t;
 end;
  for i:=1 to p do
   readln(b[i]);


  for i:=1 to n do
  for j:=1 to n do
    for k:=1 to n do
     if ((a[i,k]>a[i,j]+a[j,k]) or (a[i,k]=0))and (a[i,j]+a[j,k]<>0) and (a[i,j]<>0) and (a[j,k]<>0) then begin
     a[i,k]:=a[i,j]+a[j,k];
     a[k,i]:=a[i,k];



     end;

{ for i:=1 to n do begin
 for j:=1 to n do
   write(a[i,j],' ');
  writeln;
  end;       }


  for i:=1 to n do begin
   min:=200;
   t:=0;
   for j:=1 to p do
    if (a[i,b[j]]<min) and (i<>b[j]) then  begin min:=a[i,b[j]]; t:=j; end;
    writeln(t,' ',min);
   end;








  end.
