#define MAXN 20000
#include <stdio.h>
#include <time.h>
unsigned long ar[MAXN][MAXN];
int zali[MAXN]={0};
int main()
{
unsigned long n,k;
unsigned long i,j,c;
unsigned long p;
unsigned long min;
scanf("%lu %lu",&n,&k);
for(i=0;i<=n;i++) {for(p=0;p<=n;p++) ar[i][p]=1000000;}
for(p=0;p<n-1;p++)
   {
   scanf("%lu %lu %lu",&i,&j,&c);
   ar[i][j]=c;
   ar[j][i]=c;
   }
for(p=0;p<k;p++) {scanf("%lu",&i); zali[i]=1;}
for(i=1;i<=n;i++)
        {
	for(k=1;k<=n;k++)
	   for(j=1;j<=n;j++)
                  {
		   if(ar[i][j]+ar[j][k]<ar[i][k]) {ar[i][k]=ar[i][j]+ar[j][k];ar[k][i]=ar[i][k];}
                   }
	}
for(i=1;i<=n;i++)
	{
    min=2000000001;
    for(k=1;k<=n;k++)
		if(k!=i && zali[k]==1 && min>ar[i][k]) {min=ar[i][k]; p=k;}
        printf("%lu %lu\n",p,min);
	}
return 0;
}
