Problem:
Score : 400 points

Problem Statement

Given is a rooted tree with N vertices numbered 1 to N.
The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.

Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.

Now, the following Q operations will be performed:

Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.

Find the value of the counter on each vertex after all operations.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq Q \leq 2 \times 10^5

1 \leq a_i < b_i \leq N

1 \leq p_j \leq N

1 \leq x_j \leq 10^4

The given graph is a tree.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
a_1 b_1
:
a_{N-1} b_{N-1}
p_1 x_1
:
p_Q x_Q

Output

Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between.

Sample Input 1

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

Sample Output 1

100 110 111 110

The tree in this input is as follows:

Each operation changes the values of the counters on the vertices as follows:

Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.

Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.

Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.

Sample Input 2

6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10

Sample Output 2

20 20 20 20 20 20

Solution in Fortran (gfortran v4.8.4) (judge verdict: Accepted)

module mod_tree
  implicit none
  type arraylist
    integer :: num = 0
    integer, pointer :: arr(:) => null()
  end type
  type tree
    type(arraylist), pointer :: egs(:) => null()
    integer, pointer :: dist(:) => null()
  contains
    procedure :: add => add
    procedure :: dfs => dfs
  end type
  interface tree
    module procedure :: newt
  end interface tree
contains
  subroutine appende(a)
    integer, pointer, intent(inout) :: a(:)
    integer :: n
    integer, allocatable :: tmp(:)
    n = size(a)
    allocate(tmp(n))
    tmp = a
    deallocate(a)
    allocate(a(2*n))
    a(1:n) = tmp
    deallocate(tmp)
  end
  subroutine adde(list,e)
    class(arraylist), intent(inout) :: list
    integer, intent(in) :: e
    if (.not.associated(list%arr)) allocate(list%arr(1))
    if (list%num == size(list%arr)) call appende(list%arr)
    list%num = list%num+1
    list%arr(list%num) = e
  end
  function gete(list,i) result(ret)
    class(arraylist), intent(inout) :: list
    integer, intent(in) :: i
    integer :: ret
    ret = list%arr(i)
  end
  function newt(n) result(ret)
    integer, intent(in) :: n
    type(tree) :: ret
    allocate(ret%egs(n))
    allocate(ret%dist(n))
    ret%dist = 0
  end
  subroutine add(this,fm,to)
    class(tree), intent(inout) :: this
    integer, intent(in) :: fm, to
    call adde(this%egs(fm),to)
  end
  recursive subroutine dfs(this,v,p,d)
    class(tree), intent(inout) :: this
    integer, intent(in) :: v, p, d
    integer :: n, i, u
    this%dist(v) = d
    n = this%egs(v)%num
    do i = 1, n
      u = gete(this%egs(v),i)
      if (u == p) cycle
      call dfs(this,u,v,d+1)
    end do
  end
end module mod_tree
program abc138d
    use mod_tree
    implicit none
    integer::N,Q,P,X
    integer::i
    integer,allocatable,dimension(:)::U,T,A,B
    integer(8),allocatable,dimension(:)::D
    logical,allocatable,dimension(:)::Visited
    type(tree)::G
    read*,N,Q
    allocate(U(0:N),T(0:N),D(N),A(N-1),B(N-1))
    G=tree(N)
    do i=1,N-1
        read*,A(i),B(i)
        call add(G,A(i),B(i))
        call add(G,B(i),A(i)) 
    end do
    call dfs(G,1,-1,0)
    U=0;T=0
    do i=1,N-1
        if(G%dist(A(i))<G%dist(B(i)))then
            U(B(i))=A(i)
        else
            U(A(i))=B(i)
        endif
    end do

    do i=1,Q
        read*,P,X
        T(P)=T(P)+X
    end do
    
    allocate(Visited(0:N))
    Visited=.false.
    do i=1,N
        if(.not.visited(i))then
            call solve(i)
        endif
        print"(i0)",T(i)
    end do
contains
recursive subroutine solve(Num)
    integer::Num
    if(U(Num)/=0.and. .not.(Visited(U(Num))))then
        call solve(U(Num))
    endif
    T(Num)=T(Num)+T(U(Num))
    Visited(Num)=.true.
end subroutine
end program