program kadai
implicit none

integer  ::  n
integer  ::  q
integer,allocatable  ::  a(:)
integer,allocatable  ::  b(:)
integer,allocatable  ::  p(:)
integer,allocatable  ::  x(:)
integer,allocatable  ::  count(:)
integer,allocatable  ::  bu(:,:)
integer  ::  i , j , k

read(*,*) n,q
allocate(a(n-1))
allocate(b(n-1))
allocate(p(q))
allocate(x(q))
allocate(count(n))
allocate(bu(n,n))



do i=1,n-1
    read(*,*) a(i),b(i)
end do

do i=1,q
    read(*,*) p(i),x(i)
end do

bu=0
count=0

do i=1,n
    k=1
    do j=1,n-1
        if (a(j)==i .and. k<n+1) then
            bu(i,k)=b(j)
            k=k+1
        end if
    end do
end do

do i=1,q
    call plus(count,bu(p(i),:),x(i),n)
    j=1
    do while(bu(p(i),j)>0 .and. j<n+1)
        call plus(count,bu(bu(p(i),j),:),x(i),n)
        j=j+1
    end do

    count(p(i))=count(p(i))+x(i)

end do

write(*,*) count

stop
contains

subroutine plus(count,num,x,n)
    implicit none
    integer,intent(inout)  ::  count(:)
    integer,intent(in)  ::  num(:)
    integer,intent(in)  ::  x
    integer,intent(in)  ::  n
    integer  ::  m


    m=1
    do while(num(m)>0 .and. m<n+1)
        count(num(m))=count(num(m))+x
        m=m+1
    end do

    return
end subroutine  plus

end program kadai
