type sp = ^t;
     t = record
          vr, val : longint;
          link : sp;
         end;
     el = record
           vr, min : longint;
          end;

const maxn = 100000;

var a : array[1..maxn] of pointer;
    used, b : array[1..maxn] of longint;
    min : array[1..maxn] of el;
    check : array[1..maxn, 1..2] of longint;
    i, j, k, l, o, m, n : longint;
    p, q : sp;
    elem : el;

procedure init;
 begin
  readln(n, m);
  for i := 1 to n - 1 do
    begin
     readln(k, l, o);
     new(p);
     p^.vr := k;
     p^.val := o;
     p^.link := a[l];
     a[l] := p;
     new(p);
     p^.vr := l;
     p^.val := o;
     p^.link := a[k];
     a[k] := p;
    end;
  for i := 1 to m do
    begin
     readln(b[i]);
     check[b[i], 1] := 1;
     check[b[i], 2] := i;
    end;
 end;


procedure DFS(w, sum : longint);
var p : sp;
 begin
  used[w] := 1;
  if (check[w, 1] = 1) and (w <> b[i]) then
    begin
     if (min[w].min > sum) or (min[w].min = 0) then
       begin
        min[w].min := sum;
        min[w].vr := i;
       end;
    end
  else
    begin
     p := a[w];
     if check[w, 1] = 0 then
     if (min[w].min > sum) or (min[w].min = 0) then
       begin
        min[w].min := sum;
        min[w].vr := i;
       end;
     while p <> nil do
       begin
        if used[p^.vr] = 0 then DFS(p^.vr, sum + p^.val);
        p := p^.link;
       end;
    end;
  used[w] := 0;
 end;



begin
 init;
 for i := 1 to m do
     DFS(b[i], 0);
 for i := 1 to n do
   writeln(min[i].vr, ' ', min[i].min);
end.




