### constant

MAX_INT = (1 << 30)

### subroutines

def get_times(nd0, nd1)
  return [0, 0] if $nbrs[nd1].length == 1

  tms = $nbrs[nd1].select{|k| k != nd0}.map{|k| get_times(nd1, k)}

  min_time = MAX_INT

  for i in (0...tms.length)
    time = (0...tms.length).inject(0){|s, j| s + tms[j][(i != j) ? 0 : 1]}
    min_time = time if min_time > time
  end

  b = $bridges[nd0][nd1]
  [ 2 * b + tms.inject(0){|s, tm| s + tm[0]}, b + min_time]
end

### main

while true
  $n = gets.strip.to_i
  break if $n == 0

  $bridges = $n.times.map{$n.times.map{nil}}
  $nbrs = $n.times.map{[]}

  ($n - 1).times do
    a, b, t = gets.strip.split(' ').map{|s| s.to_i}
    a -= 1
    b -= 1

    $bridges[a][b] = $bridges[b][a] = t
    $nbrs[a] << b
    $nbrs[b] << a
  end
  #p $bridges
  #p $nbrs

  min_time = MAX_INT
  tms = $nbrs[0].map{|k| get_times(0, k)}

  for i in (0...tms.length)
    time = (0...tms.length).inject(0){|s, j| s + tms[j][(i != j) ? 0 : 1]}
    min_time = time if min_time > time
  end

  puts min_time
end