当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7215:Weighted Beautiful Tree

题目描述
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 $wn_i$ and a cost of $c_i$. The $i$-th edge connecting node $u_i$ and $v_i$ has a weight of $we_i$. The edge is called beautiful if and only if it meets $\min(wn_{u_i}, wn_{v_i}) \le we_i \le \max(wn_{u_i}, wn_{v_i})$.

You can do the following operation several times.
  • Choose a node $u$, then change its weight $wn_u$ into $wn^{\prime}_{u}$. The total cost adds $c_u \left| wn_u - wn^{\prime}_{u} \right|$.
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, the input format is as follows:

| $n$ | | | | |
|-----------|-----------|------------|----------|--------|
| $c_1$ | $c_2$ | $c_3$ | $\ldots$ | $c_n$ |
| $wn_1$ | $wn_2$ | $wn_3$ | $\ldots$ | $wn_n$ |
| $u_1$ | $v_1$ | $we_1$ | | |
| $u_2$ | $v_2$ | $we_2$ | | |
| $\vdots$ | $\vdots$ | $\vdots$ | | |
| $u_{n-1}$ | $v_{n-1}$ | $we_{n-1}$ | | |

It is guaranteed that:
  • $1\le T \le 10^3$
  • $1\le n \le 10^5$, $\sum n\le 10^6$
  • $1\le c_i, wn_i, we_i \le 10^6$

输出解释
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

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7215

最后修改于 2022-09-15T06:17:27+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 524288/524288K(Java/Others)