#include <fstream>
#include <iostream>
#include <queue>

using namespace std;

struct edge
{
 	long int v;
	long int d;
	edge* next;
} *edges[ 100001 ];

long int zali[ 100001 ];
char isz[ 100001 ];
int n, k, m;
long int dists[ 100001 ];

void init( )
{
 	long int i;
	long int u, v, di;
	edge* t;

	ifstream fin( "gpaths.in" );
	fin >> n >> k; m = n-1;

	for ( i=1; i<=n; i++ )
   {
	 	dists[ i ] = -999999;
		isz[ i ] = 0;
		zali[ i ] = 0;

		fin >> u >> v >> di;
		t = new edge;
		t->v = v;
		t->d = -di;
		t->next = edges[ u ];
		edges[ u ] = t;
   }

	for ( i=1; i<=k; i++ )
	{
		fin >> zali[ i ];
		isz[ zali[ i ] ] = i;
   }

	fin.close( );
}


struct niki
{
	long int u;
	long int d;

	bool operator < ( const niki& a ) const
	{
	 	return (a.d < d);
   }
};


long dfs( long int u )
{
	niki w;

	priority_queue<niki> q;

	w.u = u;
	w.d = 0;
	q.push( w );

	int v, d;
	char vis[ 100001 ];
	dists[ u ] = 0;

	while ( !q.empty( ) )
   {
		w = q.top( );
		q.pop( );

      v = w.u;
		d = w.d;
		vis[ v ] = 2;

		if ( d > dists[ v ] )
        	dists[ v ] = d;

		for ( edge* t=edges[ v ]; t != NULL; t = t->next )
		if ( dists[ t->v ] < d + t->d )
	   {
			w.u = t->v;
			w.d = d + t->d;

			q.push( w );
         dists[ t->v ] = d+t->d;
      }
   }
	long min = -999999, r, i;

	for ( i=1; i<=n; i++ )
      if ( dists[ i ] > min )
		{
        min = dists[ i ];
		  r = i;
		}

	return r;
}


void solve( )
{
 	int i, j;
   i = dfs( 1 );
	j = dfs( i );
	dfs( j );

   for ( i=1; i<=n; i++ )
      cout << dists[ i ]*(-1) << endl;
}


int main( )
{
 	init( );
	solve( );
}
