Scanf.scanf "%d %d" (fun n q ->
    let nei = Array.make n [] in
    for i = 1 to n - 1 do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b);
        )
    done;
    let counter = Array.make n 0 in
    for i = 1 to q do
        Scanf.scanf " %d %d" (fun p x ->
            let p = p - 1 in
            counter.(p) <- counter.(p) + x
        )
    done;

    let parent = Array.make n (-1) in
    let rec parse_parent par cur =
        parent.(cur) <- par;
        List.iter (fun v -> if v <> par then parse_parent cur v) nei.(cur)
    in
    parse_parent (-1) 0;
    let score = Array.make n (-1) in
    score.(0) <- counter.(0);
    let rec calc p =
        if score.(p) >= 0 then score.(p) else
            let s = calc parent.(p) + counter.(p) in
            let () = score.(p) <- s in
            s
    in
    for i = 0 to n - 1 do
        Printf.printf "%d "@@ calc i
    done;
    print_newline ()
)