import java.util.*
fun main(args:Array<String>?): Unit {
    while(true){
        val n = readLine()!!.toInt()
        if (n == 0) return
        val nodes = Array(n){Stack<Edge>()}
        repeat(n - 1){
            val (a, b, t) = readLine()!!.trim().split(' ').map(String::toInt)
            nodes[a - 1].push(Edge(b - 1, t))
            nodes[b - 1].push(Edge(a - 1, t))
        }
        println(solve(nodes))
    }
}
fun solve(defaultNode: Array<out Collection<Edge>>): Int {
    val depth = Array(defaultNode.size){-1}
    val queue = LinkedList<Int>()
    depth[0] = 0
    queue.add(0)
    while(queue.isNotEmpty()){
        val current = queue.pop()
        for ((to, _) in defaultNode[current]) if (depth[to] == -1){
            depth[to] = depth[current] + 1
            queue.add(to)
        }
    }
    val memoReturns = Array(defaultNode.size){null as Int?}
    val memoNotReturns = Array(defaultNode.size){null as Int?}
    val nodes = defaultNode.mapIndexed { current, node -> node.filter{depth[it.to] > depth[current] && defaultNode[it.to].size != 1}}
    fun costReturn(current: Int): Int {
        if (memoReturns[current] == null)
            memoReturns[current] = nodes[current].map{costReturn(it.to) + it.time * 2}.sum()
        return memoReturns[current]!!
    }
    fun costNotReturn(current: Int): Int {
        if (memoNotReturns[current] == null) {
            val returns = nodes[current].map { costReturn(it.to) + it.time * 2 }.sum()
            memoNotReturns[current] = nodes[current].map{
                returns - costReturn(it.to) - it.time + costNotReturn(it.to)
            }.min() ?: 0
        }
        return memoNotReturns[current]!!
    }
    costNotReturn(0)
    return costNotReturn(0)
}
data class Edge(val to: Int, val time: Int)
