#include<iostream>

using namespace std;

unsigned long INFINITY=999999;
unsigned long a, n, k;
unsigned long A[1000][1000], B[1000];

void init ()
{
        int i, j;
        for (i=1; i<=n; i++)
            for (j=1; j<=n; j++)
                A[i][j]=INFINITY;
}

void solve ()
{
        unsigned long i, j, k;
        for (i=1; i<=n; i++)
            for (j=1; j<=n; j++)
                for (k=1; k<=n; k++)
                    if (A[i][j]+A[j][k]<A[i][k])
                        A[i][k]=A[i][j]+A[j][k];
}

void vhod ()
{
        unsigned long pos, min, i, j, b, c;
        cin>>n>>k;
        init ();
        for (i=1; i<n; i++)
        {
                cin>>a>>b>>c;
                A[a][b]=A[b][a]=c;
        }

        solve ();

        for (i=0; i<k; i++)
            cin>>B[i];

        for (i=1; i<=n; i++)
        {
            min=999999;
                 for (j=0; j<k; j++)
                     if (i!=B[j] && A[i][B[j]]<min)
                        {
                         min=A[i][B[j]];
                                pos=j;
                                }
                        cout<<pos+1<<' '<<min<<endl;
            }
}
int main ()
{
        vhod ();
        return 0;
}
