unittest
{
	assert( [ "4 3", "1 2", "2 3", "2 4", "2 10", "1 100", "3 1" ].parse.expand.solve == "100 110 111 110" );
	assert( [ "6 2", "1 2", "1 3", "2 4", "3 6", "2 5", "1 10", "1 10" ].parse.expand.solve == "20 20 20 20 20 20" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nq = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nq[ 0 ] - 1 ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
		ab[] -= 1;
	}
	auto pxs = new long[ 2 ][ nq[ 1 ] ];
	foreach( ref px; pxs )
	{
		input.popFront;
		px = input.front.split.to!( long[] );
		px[ 0 ]--;
	}
	return tuple( nq[ 0 ], abs, pxs );
}

auto solve( long n, long[ 2 ][] abs, long[ 2 ][] pxs )
{
	auto ws = new long[ n ];
	foreach( px; pxs )
	{
		ws[ px[ 0 ] ] += px[ 1 ];
	}
	
	auto anss = bfsEx( n, abs, ws, 0 );
	return anss.to!( string[] ).join( " " );
}

// グラフの始点指定最短経路探索（幅優先探索）
auto bfsEx( bool undirected = false )( long n, long[ 2 ][] es, long[] ws, long s )
{
	import std.container.dlist;
	
	auto ds = new long[ n ];
	ds[] = long.max;
	ds[ s ] = ws[ s ];
	
	auto nss = new long[][ n ];
	foreach( e; es )
	{
		nss[ e[ 0 ] ] ~= e[ 1 ];
		static if( undirected ) nss[ e[ 1 ] ] ~= e[ 0 ];
	}
	
	auto queue = make!DList( s );
	while( !queue.empty )
	{
		auto f = queue.front;
		queue.removeFront();
		
		foreach( t; nss[ f ] )
		{
			if( ds[ t ] < long.max ) continue;
			ds[ t ] = ds[ f ] + ws[ t ];
			queue.insertBack( t );
		}
	}
	return ds;
}
