#include <stdio.h>
#include <limits.h>
#include <malloc.h>

int N, K;
int i;
int f, t, w;

int *ma3x;

typedef struct node {
   int br;
   int zadel;
   int *sysedi;
   int *tejesti;
} node;

node *graph;

int path(int from, int to)
{
   int i;

   for(i = 0; i < graph[from].br; i++)
   {
      if(to == graph[from].sysedi[i]) return graph[from].tejesti[i];
   }

   return INT_MAX / 2 - 1;
}

int dk(int k)
{
   int *d, i, j, min;
   int *used, pth = INT_MAX / 2 - 1;

   d = (int *) malloc((graph[k].br + 7) * sizeof(int));

   used = (int *) malloc((graph[k].br + 7) * sizeof(int));
   
   for(i = 1; i <= N; i++)
   {
      d[i] = path(k, i);
      used[i] = 0;
   }
   used[k] = 1;
   d[k] = INT_MAX / 2 - 1;

    while(1)
    {
       j = -1;
       min = INT_MAX / 2 - 1;

       for(i = 1; i <= N; i++)
       {
          if(d[i] < min && !used[i])
          {
             min = d[i];
             j = i;
          }
       }

       if(j == -1) break;

       used[j] = 1;

       for(i = 1; i <= N; i++)
       {
          if(!used[i])
          {
             pth = path(j, i);
             if(d[i] > d[j] + pth) d[i] = d[j] + pth;
          }
       }
    }

   min = INT_MAX / 2 - 1;

   for(i = 1; i <= N; i++)
   {
      if(d[ma3x[i]] < min)
      {
         min = d[ma3x[i]];
         j = i;
      }
   }

   printf("%d %d\n", j, min);
   
   free(d);
}

   
int main(void)
{
   scanf("%d%d", &N, &K);

   graph = (node *) malloc((N + 7) * sizeof(node));
   ma3x = (int *) malloc((K + 7) * sizeof(int));

   for(i = 1; i <= N; i++)
   {
      ma3x[i] = 0;
      graph[i].sysedi = (int *) malloc(2 * sizeof(int));
      graph[i].tejesti = (int *) malloc(2 * sizeof(int));
      graph[i].br = 0;
      graph[i].zadel = 2;
   }

   for(i = 1; i < N; i++)
   {
      scanf("%d%d%d", &f, &t, &w);

      if(graph[f].br >= graph[f].zadel)
      {
         graph[f].sysedi = (int *) realloc(graph[f].sysedi, graph[f].zadel * 2 * sizeof(int));
         graph[f].tejesti = (int *) realloc(graph[f].tejesti, graph[f].zadel * 2 * sizeof(int));
         graph[f].zadel *= 2;
      }
      if(graph[t].br >= graph[t].zadel)
      {
         graph[t].sysedi = (int *) realloc(graph[t].sysedi, graph[t].zadel * 2 * sizeof(int));
         graph[t].tejesti = (int *) realloc(graph[t].tejesti, graph[t].zadel * 2 * sizeof(int));
         graph[t].zadel *= 2;
      }

      graph[f].sysedi[graph[f].br] = t;
      graph[f].tejesti[graph[f].br] = w;

      graph[t].sysedi[graph[t].br] = f;
      graph[t].tejesti[graph[t].br] = w;
      graph[f].br++;
      graph[t].br++;
   }

   for(i = 1; i <= K; i++) scanf("%d", &ma3x[i]);
   
   for(i = 1; i <= N; i++) dk(i);

   free(graph);
   return 0;
}

      

   

   
   
