open System
open System.Collections.Generic

let toTuple xs =
    match xs with
    | [| a ; b |] -> (a, b)
    | _           -> failwith "invalid arguments"

let readIntTuple () =
    Console.ReadLine ()
    |> fun s -> s.Split(' ')
    |> Array.map int
    |> toTuple

type Graph = list<int> array
type Queries = Dictionary<int,int>

let dfsFactory (G: Graph) (Q: Queries) (A: inref<int array>) =
    let rec dfs p p' acc =
        let acc' = acc + Q.Item p

        A.[p] <- acc'

        for child in G.[p] do
            if child <> p' then dfs child p acc'

        ()

    dfs

[<EntryPoint>]
let main argv =
    let N, Q = readIntTuple ()

    let edges = seq { for _ in 1 .. N - 1 -> readIntTuple () }
                |> Seq.map (fun (a, b) -> (a - 1, b - 1))

    let queries' = seq { for _ in 1 .. Q -> readIntTuple () }
                   |> Seq.map (fun (p, q) -> (p - 1, q))

    let G = [| for _ in 1 .. N -> [] |]

    for a, b in edges do
        G.[a] <- b :: G.[a]
        G.[b] <- a :: G.[b]

    let queries = new Queries ()

    for p in 0 .. N - 1 do
        queries.Add (p, 0)

    for p, q in queries' do
        queries.Item p <- queries.Item p + q

    let A = [| 1 .. N |]

    let dfs = dfsFactory G queries &A

    dfs 0 -1 0

    A
    |> Seq.map string
    |> String.concat " "
    |> printfn "%s"

    0
