n, q = gets.split.map(&:to_i)

APEXES = []
loop do
  APEXES += (gets&.split&.map(&:to_i) || break)
end
processes = APEXES.pop(q)

result = Array.new(n) { 0 }

processes.each do |target_root, value|
  targets = [target_root]

  children = [target_root]
  until children.empty?
    child = children.shift
    target_children = APEXES.select do |apex|
      apex[0] == child
    end
    children += target_children.map { |t| t[1] }
    targets |= children
  end

  targets.each do |target|
    result[target - 1] += value
  end
end

puts result
