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

## recursive version
# def f(i, j, g)
#   unless $known[i][j]
#     max = 0
#     g[j].child.each{|k, w|
#       next if i == k
#       ret = f(j, k, g)
#       max = ret if max < ret
#     }
#     $known[i][j] = g[i].child[j] + max
#   end
#   return $known[i][j]
# end

def f(i, j, g)
  n = g.size
  stack = [i, j]
  max = Array.new(n){0}
  done = {}
  done[i] = true
  while stack.size > 1
    s = stack[-2]
    t = stack[-1]
    flag = true
    key = "#{s} #{t}"
    unless $known[key]
      g[t].child.each{|u, w|
        next if done[u]
        next if s == u
        stack << u
        done[u] = true
        flag = false
        break
      }
      if flag
        $known[key] = g[s].child[t] + max[t]
        max[s] = $known[key] if max[s] < $known[key]
        stack.pop
      end
    else
      max[s] = $known[key] if max[s] < $known[key]
      stack.pop
    end
  end
  # p $known
  # p max
  return $known["#{i} #{j}"]
end

# $known = Hash.new{|h, k| h[k] = {}}
$known = {}
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|
  max = 0
  g[i].child.each{|j, w|
    ret = f(i, j, g)
    max = ret if max < ret
  }
  puts max
}