'use strict'

function main(inp) {
  inp = inp.trim().split('\n')
  const NQ = inp.shift().split(' ').map(n => Number(n))
  let node = {}
  for (let i = 1; i <= NQ[0]; i++) {
    node[i] = {score: 0, next: []}
  }

  for (let i = 0; i < inp.length; i++) {
    const arr = inp[i].split(' ').map(n => Number(n))
    let j = arr[0]
    if (i < NQ[0] - 1) {
      node[j].next.push(arr[1])
    } else {
      node[j].score += arr[1]
    }
  }

  let stack = [1]
  while(stack.length) {
    let n = stack.pop()
    for (let i = 0; i < node[n].next.length; i++) {
      let j = node[n].next[i]
      node[j].score += node[n].score
      stack.push(j)
    }
  }
  
  let ans = []
  for (let i = 1; i <= NQ[0]; i++) ans.push(node[i].score)
  console.log(ans.join(' '))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
