const
	maxn		=100000;
type
        integer         = longint;
	uk		= ^popo;
	popo		= record
				v,st	: integer;
				next	: uk;
			end;

var
	M	: array[1..maxn] of uk;
	last	: array[1..maxn] of uk;
	R1,R2	: array[1..maxn] of integer;
	PP	: array[1..maxn] of integer;
	N,P	: longint;
	used	: array[1..maxn] of boolean;
	pred	: integer;
        i,j     : integer;

        procedure add(a,b,c       : integer);
                begin
			if M[a]=nil then
				begin
					new(M[a]);
					M[a]^.v:=b;
					M[a]^.st:=c;
					M[a]^.next:=nil;
					last[a]:=M[a];
				end
			else
				begin
					new(last[a]^.next);
					last[a]:=last[a]^.next;
					last[a]^.v:=b;
					last[a]^.st:=c;
					last[a]^.next:=nil;
				end;
                end;

procedure read_inp;
var
	i,j,t,z,k	: longint;
begin

	readln(N,P);
	for i := 1 to N-1 do
		begin
			readln(t,z,k);
                        add(t,z,k);
                        add(z,t,k);
		end;
	PP[N]:=-1;
	j:=0;
	for i := 1 to P do
		begin
			readln(PP[i]);
		end;
end;

procedure dfs(index	: integer);
var
	tmp	: uk;
        buf     : integer;
begin
	tmp:=M[index];
        Used[index]:=true;
	while tmp<>nil do
		begin
			if not Used[tmp^.v] then
                           if index=PP[i] then
                              begin
                                   if R1[tmp^.v]>tmp^.st then
                                      begin
                                           R1[tmp^.v]:=tmp^.st;
                                           R2[tmp^.v]:=i;
                                           dfs(tmp^.v);
                                      end
                                   else
                                     begin
                                        buf:=R1[tmp^.v];
                                        R1[tmp^.v]:=tmp^.st;
                                        dfs(tmp^.v);
                                        R1[tmp^.v]:=buf;
                                    end;
                              end
                           else
				if (R1[tmp^.v]>(tmp^.st+R1[index])) then
					begin
						R1[tmp^.v]:=tmp^.st+R1[index];
                                                R2[tmp^.v]:=i;
						dfs(tmp^.v);
					end
				else
                                    begin
                                        buf:=R1[tmp^.v];
                                        R1[tmp^.v]:=R1[index]+tmp^.st;
                                        dfs(tmp^.v);
                                        R1[tmp^.v]:=buf;
                                    end;
			tmp:=Tmp^.next;
		end;
        used[index]:=false;
end;

begin
     read_inp;
     for i := 1 to N do
         R1[i]:=30000;
     for i := 1 to P do
         begin
                 dfs(PP[i]);
         end;
     for i := 1 to N do
         begin
              writeln(R2[i],' ',R1[i]);
         end;

end.