var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    main(input)
});

function main(input){
    var args = input.trim().split('\n');

    var i = 0;
    while(true) {
        var islandCount = parseInt(args[i++]);
        if(isEnd(islandCount)) break;

        var islands = {};
        for(var j = 1; j <= islandCount; j += 1){
            islands[j] = {};
        }

        for(var j = 0; j < islandCount - 1; j += 1){
            var bridgeData = splitNum(args[i++]);
            var a = bridgeData[0], b = bridgeData[1];
            islands[a][b] = islands[b][a] = bridgeData[2];
        }

        console.log(bombRecursively(1, null, islands));

    }
}

function bombRecursively(current, parent, islands){

    var island = islands[current];

    var total = 0;
    for(var nextIslandIdx in island){
        if(nextIslandIdx === parent){ continue; }

        var nextIsland = islands[nextIslandIdx];
        if(isEndIsland(nextIsland)){
            delete island[nextIslandIdx];
            continue;
        }
        total += island[nextIslandIdx];
        total += bombRecursively(nextIslandIdx, current, islands);
    }
    var parentIsland = islands[parent] || {};
    if(!isEndIsland(parentIsland)){
        total += island[parent];
    }
    delete parentIsland[current];

    return total;
}

function isEndIsland(island){
    return Object.keys(island).length <= 1;
}

function splitNum(str){
    return str.split(' ').map(Number);
}

function isEnd(arg){
    return arg === 0;
}