#include <stdio.h>
#include <math.h>
#include<iostream.h>


unsigned sttown[10][10];
unsigned gameplace[100];
unsigned N,K,F,S=0;
int i,j;
int queue[100][2];


inline int findGP(int x)
 { int br;
  for(j=0;j<K;j++)
		if(gameplace[j]-1==x)
				br= j;
	 return br;  }


 inline int checkGP(int x)
{  for(j=0;j<K;j++)
	         if(gameplace[j]-1==x)
				return 1;
 return 0;
 }


inline  void check(int x)
 { if(queue[x][0]){if(queue[x][1]>S){queue[x][1]=S;queue[x][0]=F; }  }
	else queue[x][1]=S;queue[x][0]=F;
     };


 inline void bfs(int x,int y)
 { for(i=0;i<N;i++)
		if(sttown[x][i]!=0)
		if(checkGP(i)) {S=S+sttown[x][i];F=findGP(i);check(y);}
			  else {S=S+sttown[x][i];bfs(i,y);};

		return ;
		}


int main()
{ 
 
  scanf("%d %d",&N, &K);
  for(i=0;i<N;i++)for(j=0;j<N;j++) sttown[i][j]=0;
  for(i=0;i<N-1;i++)
	 { int r,t,q;
	   cin>>r>>t>>q; 
      sttown[r-1][t-1]=q;
	   sttown[t-1][r-1]=q;}

  for(i=0;i<K;i++)
	  cin>>gameplace[i];

  for(i=0;i<N;i++)for(j=0;j<2;j++)queue[i][j]=0;

  for(i=0;i<N;i++)
    {for(i=0;i<N;i++)for(j=0;j<2;j++)queue[i][j]=0;
     S=0;F=0;
	  bfs(i,i);
	  cout<<"\n"<<queue[i][0]<<" "<<queue[i][1];}

     return 0;
}
