INF = 1000000

until (n = gets.to_i).zero?
  edge = Array.new
  degree = Array.new(n){0}
  (n - 1).times do
    from, to, weight = gets.split.map(&:to_i)
    from -= 1
    to -= 1
    edge << [from, to, weight]
    degree[from] += 1
    degree[to] += 1
  end

  (1...n).each do |i|
    next unless degree[i] == 1
    edge.reject! do |(from, to, weight)| from == i || to == i end
  end

  answer = edge.empty? ? 0 : edge.map{|e| e.last}.inject(&:+) * 2

  cost = Array.new(n){Array.new(n){INF}}
  edge.each do |(from, to, weight)| cost[from][to] = cost[to][from] = weight end
  n.times do |i| cost[i][i] = 0 end
  n.times do |k|
    n.times do |i|
      n.times do |j|
        cost[i][j] = [cost[i][j], cost[i][k] + cost[k][j]].min
      end
    end
  end
  answer -= cost[0].select{|v| v != INF}.max

  p answer
end