CF1637F.Towers
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree with n vertices numbered from 1 to n. The height of the i-th vertex is hi. You can place any number of towers into vertices, for each tower you can choose which vertex to put it in, as well as choose its efficiency. Setting up a tower with efficiency e costs e coins, where e>0.
It is considered that a vertex x gets a signal if for some pair of towers at the vertices u and v (u=v, but it is allowed that x=u or x=v) with efficiencies eu and ev, respectively, it is satisfied that min(eu,ev)≥hx and x lies on the path between u and v.
Find the minimum number of coins required to set up towers so that you can get a signal at all vertices.
给你一棵包含 n 个顶点的树,顶点编号为 1 到 n。第 i 个顶点的高度为 hi。你可以在任意多个顶点上放置信号塔;对于每座塔,你可以自由选择其放置的顶点以及其效率值。设置一座效率为 e 的塔需要花费 e 枚金币,其中 e>0。
称顶点 x 接收到信号,当且仅当存在两座位于顶点 u 和 v(u=v;但允许 x=u 或 x=v)的塔,其效率分别为 eu 和 ev,满足:
min(eu,ev)≥hx,且 x 位于 u 与 v 之间的唯一路径上。
求使所有顶点均能接收到信号所需的最少金币数。
输入格式
The first line contains an integer n (2≤n≤200000) — the number of vertices in the tree.
The second line contains n integers hi (1≤hi≤109) — the heights of the vertices.
Each of the next n−1 lines contain a pair of numbers vi,ui (1≤vi,ui≤n) — an edge of the tree. It is guaranteed that the given edges form a tree.
第一行包含一个整数 n(2≤n≤200000)—— 树中顶点的数量。
第二行包含 n 个整数 hi(1≤hi≤109)—— 各顶点的高度。
接下来的 n−1 行,每行包含一对数字 vi,ui(1≤vi,ui≤n)—— 树的一条边。保证所给的边构成一棵树。
输出格式
Print one integer — the minimum required number of coins.
输出一个整数——所需的最少硬币数量。
输入输出样例
输入#1
3 1 2 1 1 2 2 3
输出#1
4
输入#2
5 1 3 3 1 3 1 3 5 4 4 3 2 3
输出#2
7
输入#3
2 6 1 1 2
输出#3
12
说明/提示
In the first test case it's optimal to install two towers with efficiencies 2 at vertices 1 and 3.
In the second test case it's optimal to install a tower with efficiency 1 at vertex 1 and two towers with efficiencies 3 at vertices 2 and 5.
In the third test case it's optimal to install two towers with efficiencies 6 at vertices 1 and 2.
在第一个测试用例中,最优方案是在顶点 1 和 3 处各安装一座效率为 2 的塔。
在第二个测试用例中,最优方案是在顶点 1 处安装一座效率为 1 的塔,并在顶点 2 和 5 处各安装一座效率为 3 的塔。
在第三个测试用例中,最优方案是在顶点 1 和 2 处各安装一座效率为 6 的塔。
输入解题思路,AI测评打分。不知道怎么写?