stdin.ReadLine()
|> fun x -> x.Split() |> Array.map int |> fun x -> (x.[0], x.[1])
|> fun (n, q) ->
  (
    List.init (n - 1) (fun _ -> stdin.ReadLine() |> fun x -> x.Split() |> Array.map int |> fun x -> (x.[0], x.[1])),
    List.init q       (fun _ -> stdin.ReadLine() |> fun x -> x.Split() |> Array.map int |> fun x -> (x.[0], x.[1]))
  )
  |> fun (nabs, qpxs) ->
    (
      (nabs @ (nabs |> List.map (fun (a, b) -> (b, a))))
      |> List.fold (
        fun map (a, b) ->
          map
          |> Map.tryFind a
          |> fun cs ->
            match cs with
            | Some cs -> map.Remove(a).Add(a, b::cs)
            | None -> map.Add(a, [b])
      ) Map.empty,
      qpxs
      |> List.fold (
        fun (arr: int array) (p, x) ->
          (arr.[p] <- arr.[p] + x)
          |> fun () -> arr
      ) (Array.zeroCreate (n + 1))
    )
  |> fun (edges, points) ->
    (
      [| [(0, 1)] |],
      Array.concat [ [| 0 |]; Array.create (n) (-1) ]
    )
    |> fun ((stack: (int * int) list array), (ret: int array)) ->
      Seq.initInfinite (
        fun _ ->
          match stack.[0] with
          | [] -> ()
          | (pi, ci)::ts ->
            if ret.[ci] >= 0
            then (stack.[0] <- ts)
            else (
              (ret.[ci] <- ret.[pi] + points.[ci])
              |> fun () ->
                edges
                |> Map.tryFind ci
                |> fun cs ->
                  match cs with
                  | Some cs -> (stack.[0] <- ((cs |> List.map (fun i -> (ci, i))) @ ts))
                  | None -> (stack.[0] <- ts)
            )
      )
      |> Seq.takeWhile (fun _ -> stack.[0] |> List.isEmpty |> not)
      |> Seq.length
    |> fun _ -> ret
|> fun ret ->
  ret
  |> Array.skip 1
  |> Array.map string
  |> String.concat " "
|> printfn "%s"

// -----

// 4 3
// 1 4
// 1 3
// 2 3
// 2 10
// 1 100
// 3 1

// edges: map [(1, [3; 4]); (2, [3]); (3, [2; 1]); (4, [1])]
// points: [|0; 100; 10; 1; 0|]
// ret: [|0; -1; -1; -1; -1|]

// pi: 0, ci: 1, stack: [(0, 1)]
//   ret: [|0; 100; -1; -1; -1|]
//   cs: Some [3; 4]
// pi: 1, ci: 3, stack: [(1, 3); (1, 4)]
//   ret: [|0; 100; -1; 101; -1|]
//   cs: Some [2; 1]
// pi: 3, ci: 2, stack: [(3, 2); (3, 1); (1, 4)]
//   ret: [|0; 100; 111; 101; -1|]
//   cs: Some [3]
// pi: 1, ci: 4, stack: [(1, 4)]
//   ret: [|0; 100; 111; 101; 100|]
//   cs: Some [1]

// 100 111 101 100
