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

def visit(p, v, g)
  d = []
  dmax = 0
  pos = v
  stack = [p, v]
  g[v].visited = true
  while stack.size > 1
    p = stack[-2]
    v = stack[-1]
    flag = true
    g[v].child.each{|dst, w|
      next if g[dst].visited
      if dst != p
        g[dst].visited = true
        stack << dst
        d << w
        flag = false
        break
      end
    }
    if flag == true
      break if d.size == 0
      dia = d.inject(:+)
      if dmax < dia
        dmax = dia
        pos = v
      end
      stack.pop
      d.pop
    end
  end
  return dmax, pos
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)
n.times{|i|
  g[i].visited = false
}
t = visit(-1, r[1], g)

puts t[0]