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

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

$known = Hash.new{|h, k| h[k] = {}}
$m = {}
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)
    if max < ret
      max = ret
      $m[i] = [j, max]
    end
  }
  puts max
}