#include <stdio.h>

long long graf[100000][1000];


long long zali[100000];
long long dist[100000],dist2[100000];
long long visited[100000];
long long start;

void extdfs(long long n,long long dis)
{long long i;

if (dist[n]==dis)
		{if (dist2[n]>start) dist2[n]=start;}
if (dist[n]>dis && dis)
		{dist[n]=dis;
		dist2[n]=start;
		}


visited[n]=1;
for (i=1;i<=graf[n][0];i++)
	{if (!visited[graf[n][i*2-1]])
		if (zali[graf[n][i*2-1]])
			{if (dist[graf[n][i*2-1]]==dis+graf[n][i*2])
				if (dist2[graf[n][i*2-1]]>start) dist2[graf[n][i*2-1]]=start;
			if (dist[graf[n][i*2-1]]>dis+graf[n][i*2])
					{dist[graf[n][i*2-1]]=dis+graf[n][i*2];
					dist2[graf[n][i*2-1]]=start;}
			}
		else extdfs(graf[n][i*2-1],dis+graf[n][i*2]);
	}
return;
}


int main (void)
{
long long N,K,i,j,t,t2,t3,x;
scanf ("%ld %ld",&N,&K);
for (i=1;i<=N;i++)
	{
	dist[i]=1999999999;
	dist2[i]=100001;
	}
for (i=1;i<N;i++)
{
scanf("%ld %ld %ld", &t, &t2, &t3);
x=graf[t][0]+1;
graf[t][x*2-1]=t2;
graf[t][x*2]=t3;
graf[t][0]++;
x=graf[t2][0]+1;
graf[t2][x*2-1]=t;
graf[t2][x*2]=t3;
graf[t2][0]++;
}

for (j=1;j<=K;j++)
{scanf("%ld", &t);
zali[t]=j;}

for (i=1;i<=N;i++)
if (zali[i])
	{start=i;
	for (j=0;j<=N;j++)
		visited[j]=0;
	extdfs(i,0);}

for (i=1;i<=N;i++)
{printf ("%ld ",zali[dist2[i]]);
printf("%ld\n",dist[i]); }

return 0;
}
