8630: Weighted Beautiful Tree

内存限制:128 MB 时间限制:5 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

A tree is a connected graph with n nodes and n-1 edges.

You are given a weighted tree with n nodes. The i-th node has a weight of wni and a cost of ci. The i-th edge connecting node ui and vi has a weight of wei. The edge is called beautiful if and only if it meets min(wnui,wnvi)weimax(wnui,wnvi).

You can do the following operation several times.

  • Choose a node u, then change its weight wnu into wnu. The total cost adds cuwnuwnu.
What is the minimum total cost to make all edges beautiful?

输入格式

The first line contains an integer T, denoting the number of test cases.



输出格式

For each test case, output an integer in a single line, denoting the minimum total cost.

输入样例 复制

2
3
2 1 2
9 9 10
1 2 10
1 3 11
3
1 1 2
9 9 10
1 2 10
1 3 11

输出样例 复制

3
2