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

def visit(p, v, g)
  r = [0, v]
  g[v].child.each{|dst, w|
    if dst != p
      t = visit(v, dst, g)
      t[0] += w
      r = t.clone if r[0] < t[0]
    end
  }
  return r
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
}

r = visit(-1, 0, g)
t = visit(-1, r[1], g)

puts t[0]