import Control.Monad
import Control.Monad.ST
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map as M
import Data.Array.ST
import Data.Array.IArray

mapFromList :: Ord k => [(k,v)] -> M.Map k [v]
mapFromList []         = M.empty
mapFromList ((k,v):xs) = M.insertWith (\[a] b -> a:b) k [v] $ mapFromList xs

solve :: Int -> [(Int,Int)] -> [(Int,Int)] -> ST s (STArray s Int Int)
solve n a p = do
    let m = mapFromList a
        ia = listArray (1,n) $ map (\i ->
            M.findWithDefault [] i m) [1..n] :: Array Int [Int]
    ma <- newArray (1,n) 0
    mapM_ (uncurry (f ia ma)) p
    return ma
  where
    f ia ma pk pv = do
        v <- readArray ma pk
        writeArray ma pk (v+pv)
        forM_ (ia!pk) (\i -> f ia ma i pv) 
        return ma

main :: IO ()
main = do
    let tuple [a,b] = (a,b)
    [n,q] <- map read . words <$> getLine :: IO [Int]
    a <- replicateM (n-1) $ tuple
        . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    p <- replicateM q $ tuple
        . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    mapM_ print . elems $ runSTArray $ solve n a p
