class Node
  attr_accessor :child, :visited
  def initialize
    @child = {}
  end
end

def visit(p, v, g)
  d = []
  dia = 0
  dmax = 0
#  pos = v
  stack = [p, v]
  visited = {}
  visited[v] = true
  while stack.size > 1
    p = stack[-2]
    v = stack[-1]
    flag = true
    g[v].child.each{|dst, w|
      next if visited[dst]
      if dst != p
        visited[dst] = true
        stack << dst
        dia += w
        d << w
        flag = false
        break
      end
    }
    if flag == true
      break if d.size == 0
      if dmax < dia
        dmax = dia
#        pos = v
      end
      stack.pop
      dia -= d.pop
    end
  end
  return dmax
end

n = gets.to_i
g = Array.new(n){Node.new}
(n-1).times{
  s, t, w = gets.split.map(&:to_i)
  g[s].child[t] = w
  g[t].child[s] = w
}

n.times{|i|
  puts visit(-1, i, g)
}