module Main where

import Data.List
import Control.Monad
import Control.Monad.ST (runST)
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import Data.Function (fix)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [(Int, Int)] -> [(Int, Int)] -> [Int]
solve n abList pxList = runST $ do
        graph <- MV.replicate (n + 1) []
        forM_ abList $ \(a, b) -> do 
            MV.modify graph (a:) b
            MV.modify graph (b:) a
        points <- UMV.replicate (n + 1) 0
        forM_ pxList $ \(p, x) -> UMV.modify points (+x) p
        let dfs = fix $ \next point parent -> do
                myPoint <- UMV.read points point
                sons <- MV.read graph point
                forM_ sons $ \son ->
                    if son == parent then return ()
                    else do 
                        UMV.modify points (+myPoint) son
                        next son point
        dfs 1 (negate 1)
        frozenAns <- UV.freeze points
        pure . tail $  UV.toList frozenAns


main = do
    (n, q) <- readTuple2
    abList <- replicateM (n - 1) readTuple2
    pxList <- replicateM q readTuple2
    putStrLn $ unwords  $ show <$> solve n abList pxList
