program gpaths;
const
  MAXN = 3000;
  INFINITY = High(longword);
var
  N,K,a,b,c,i:integer;
  cmin:longword;
  ADJ:array[1..MAXN,1..MAXN] of longword;
  GR:array[1..MAXN] of integer;

procedure floyd;
var
  k,i,j:word;
begin
  for i:=1 to N do
  for j:=1 to N do
    if (ADJ[i][j] = 0) then ADJ[i][j]:=INFINITY;

  for k:=1 to N do
    for i:=1 to N do
      for j:=1 to N do
        if((ADJ[i][k] < INFINITY)and(ADJ[k][j] < INFINITY)) then
        if(ADJ[i][j] > ADJ[i][k] + ADJ[k][j])
        then ADJ[i][j] := ADJ[i][k] + ADJ[k][j];

  for i:=1 to N do
    ADJ[i][i]:=INFINITY;
end;

begin
  readln(N,K);
  for i:=1 to N-1 do
  begin
    readln(a,b,c);
    ADJ[a][b] := c;
    ADJ[b][a] := c;
  end;

  for i:=1 to K do
  begin
    readln(a);
    GR[a] := i;
  end;

  floyd;

  for i:=1 to N do
  begin
    cmin:=INFINITY;
    for a:=1 to N do
    if (i <> a) then
      if ((cmin > ADJ[i][a])and(GR[a]<>0)) then
      begin
        cmin := ADJ[i][a];
        b := GR[a];
      end;

    writeln(b,' ',cmin);
  end;
end.
