import qualified Data.IntMap as M
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as V
import Data.List

main = do
  [n,q] <- getIntList
  edges <- getIntNTuples (n-1)
  pxs   <- getIntNTuples q
  putStr $ unwords $ map show $ solve n q edges pxs

solve :: Int -> Int -> [(Int,Int)] -> [(Int,Int)] -> [Int]
solve n q edges pxs = dfs [(1,0)] M.empty tree where
  tree = foldl (\t (a,b)->M.adjust (b:) a t)
    (M.fromDistinctAscList $ zip [1..n] (repeat [])) edges
  counter = V.fromList $ map (sum.map snd) $ groupBy (\(a,_)(b,_)->a==b) $ sortBy (\(a,_)(b,_)->compare a b) $ zip[1..n](repeat 0)++pxs
  --dfs :: [(Int,Int)] -> M.Map Int Int -> M.Map Int [Int] -> [Int]
  dfs [] ans _ = map snd $ M.toAscList ans
  dfs ((v,c):vs) ans tree = dfs
    (zip (tree M.! v) (repeat new) ++ vs)
    (M.insert v new ans)
    (M.delete v tree)
    where new = c + counter V.! (v-1)

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined
readInt = fromInteger . fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM n BS.getLine
