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
      |> List.fold (
        fun map (a, b) ->
          map
          |> Map.tryFind a
          |> fun t ->
            match t with
            | Some cs -> map.Remove(a).Add(a, b::cs)
            | None -> map.Add(a, [b])
      ) Map.empty,
      (0, 1)::nabs
      |> List.map (fun (a, b) -> (b, a))
      |> Map.ofList,
      qpxs
      |> List.fold (
        fun (arr: int array) (p, x) ->
          (arr.[p] <- arr.[p] + x)
          |> fun () -> arr
      ) (Array.zeroCreate (n + 1))
    )
  |> fun (pcs, ps, (ret: int array)) ->
    ([| [1] |])
    |> fun (stack: int list array) ->
      Seq.initInfinite (
        fun _ ->
          match stack.[0] with
          | [] -> ()
          | i::ts ->
            ps
            |> Map.find i
            |> fun pi -> (ret.[i] <- ret.[pi] + ret.[i])
            |> fun () ->
              pcs
              |> Map.tryFind i
              |> fun cs ->
                match cs with
                | Some cs -> (stack.[0] <- cs @ 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"
