#include <stdio.h>

#define MAXN		 100001
#define MAX_VALUE	 1850000000

typedef struct node{
        int w[4];
	int cost[4];
	char iz;
	char current;
}node;

typedef struct first{
        long long cost;
        int z;
}first;

node p[MAXN]={0};
first f[MAXN]={0};
int zali[MAXN]={0};
int n, k, fst, cost, i;

void readInput(void)
{
 int i, start, end, cost;
 scanf("%d%d", &n, &k);

 for(i=1; i<n; i++)
 {
    scanf("%d%d%d", &start, &end, &cost);
    p[end].w[p[end].current] = start;
    p[end].cost[p[end].current++] = cost;
    p[start].w[p[start].current] = end;
    p[start].cost[p[start].current++] = cost;
 }						//30
 for(i=0; i<k; i++)
 {
    scanf("%d", &start);
    p[start].iz = 1;
    zali[start] = i+1;
 }
}

void init_z(int i, int cost)
{
 if(i == fst) return;
 if(f[i].cost > cost)				//40
 {
  f[i].cost = cost;
  f[i].z = fst;
  if(p[i].iz==1)
  {
    if(cost < f[fst].cost)
    {
      f[fst].cost = cost;
      f[fst].z = i;
    }
    return;
  }
  if(p[i].w[0]!=0) init_z(p[i].w[0], p[i].cost[0]+cost);  
  if(p[i].w[1]!=0) init_z(p[i].w[1], p[i].cost[1]+cost);	     
  if(p[i].w[2]!=0) init_z(p[i].w[2], p[i].cost[2]+cost);     
  if(p[i].w[3]!=0) init_z(p[i].w[3], p[i].cost[3]+cost);
 }
 return;
}


void solve(void)
{
    int i, temp, j;				//60
    for(i=0; i<=n; i++)
        f[i].cost = MAX_VALUE;

    for(i=1; i<=n; i++)
    {
     if(p[i].iz == 1)
     {
      fst = i;
      if(p[i].w[0]!=0) init_z(p[i].w[0], p[i].cost[0]);
      if(p[i].w[1]!=0) init_z(p[i].w[1], p[i].cost[1]);	     
      if(p[i].w[2]!=0) init_z(p[i].w[2], p[i].cost[2]);     
      if(p[i].w[3]!=0) init_z(p[i].w[3], p[i].cost[3]);
     }						//70
    }
   						//80
return;						
}

void writeOutput(void)
{
 int i;
 for(i=1; i<=n; i++)
    printf("%d %d\n", zali[f[i].z], f[i].cost);
 return;					//90
}
						
int main()
{
 readInput();
 solve();
 writeOutput();
 return 0;
}			
						//99

