import Foundation

class Node{
    var next:[Node]=[]
    var ten:Int=0
    init() {
    }
    func plus(xs:Int){
        self.ten += xs
        if !self.next.isEmpty{
           // print("!self.next.isEmpty :",!self.next.isEmpty)
            for i in 0...self.next.count-1{
              //  print("i:",i)
                self.next[i].plus(xs:xs)
            }
        }
    }
}

func readInts(by separator: Character = " ") -> [Int] {
    return readLine()!.split(separator:separator).map { Int($0)! }
}

let n:[Int] = readInts()

var node:[Node]=[]

for i in 1...n[0]{
    node.append(Node())
}

for i in 1...n[0]-1{
    let a:[Int]=readInts()
    //print("a:",a)
    node[a[0]-1].next.append(node[a[1]-1])
   // print(node[a[0]-1].next)
}

for i in 1...n[1]{
    let p:[Int]=readInts()
  //  print("p:",p)
    node[p[0]-1].plus(xs:p[1])
}

node.map{print(($0).ten)}
    

