program zad3;
type  zapis=record
       aa:0..1;
       dl:1..100;
       end;
  var a:array[1..100,1..100] of zapis;
      b:array[1..100] of 1..100;
     n,k,p,i,j,c,br,cc,put:word;
  procedure try(var c:word;x:word);
  var i: word;
   begin
    for i:=1 to k do if (j=b[i] ) then begin  c:=i; exit; end;
    end;
  procedure probA(x:word;br:longint; var cc,put:word);
     var       f:boolean;
               p:word;
    begin
    try(c,x);
    cc:=c;
        if   (br<>0) and (br<put) then   put:=br
       else for p:= 1 to   n   do if  a[x,p].aa=1  then begin
                                                   br:=br+a[x,p].dl;
                                                   a[x,p].aa:=0;
                                                   proba(p,br,cc,put);
                                                   br:=br- a[x,p].dl;
                                                   a[x,p].aa:=1;
                                                   end;
                                   end;
   begin
  readln(n,k);
  fillchar(a,sizeof(a),0);

  for p:= 1 to n-1 do begin
                    readln(i,j,c);
                    a[i,j].aa:=1;
                    a[i,j].dl:=C;
                    end;
  for p:= 1 to k do  readln(b[p]);
  put:=100;
  cc:=0;
  writeln;
  br:=0;
  for j:=1 to n do begin
                   proba(j,br,cc,put);writeln(cc,put:5); end;
  readln;
  end.


