luogu#P10928. 走廊泼水节

走廊泼水节

Problem Description

Given a tree with NN nodes, you need to add some edges to extend this tree into a complete graph, while ensuring that the unique minimum spanning tree of the graph is still this tree.

Find the minimum possible total weight of the added edges.

Note: All edge weights in the tree are integers, and all newly added edge weights must also be integers.

Input Format

The first line contains an integer tt, meaning there are tt groups of testdata.

For each group of testdata, the first line contains an integer NN.

The next N1N-1 lines each contain three integers X,Y,ZX, Y, Z, meaning there is an edge between node XX and node YY with length ZZ.

Output Format

For each group of testdata, output one integer, meaning the minimum total weight.

Each result occupies one line.

2
3
1 2 2
1 3 3
4
1 2 3
2 3 4
3 4 5 
4
17

Hint

Constraints: 1t101 \le t \le 10, 1N60001 \le N \le 6000, 1Z1001 \le Z \le 100.

Translated by ChatGPT 5