CF437C.The Child and Toy
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as v__i. The child spend _v__f_1 + _v__f_2 + ... + v__f__k energy for removing part i where _f_1, _f_2, ..., f__k are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
儿童节那天,孩子收到了 Delayyy 送的一个玩具作为礼物。然而,这个孩子非常调皮,迫不及待地想要把这个玩具拆掉。
该玩具由 n 个部件和 m 根绳子组成。每根绳子连接两个部件,但任意两个部件之间至多只有一根绳子相连。为了彻底拆解玩具,孩子必须移除所有部件。每次只能移除一个部件,且每次移除操作都会消耗能量。定义第 i 个部件的能量值为 vi。当孩子移除部件 i 时,他所消耗的能量为 vf1+vf2+⋯+vfk,其中 f1,f2,…,fk 是所有直接与部件 i 相连且尚未被移除的部件的编号。
请帮孩子算出:要移除全部 n 个部件,他所需的最小总能量是多少?
输入格式
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: _v_1, _v_2, ..., v__n (0 ≤ v__i ≤ 105). Then followed m lines, each line contains two integers x__i and y__i, representing a rope from part x__i to part y__i (1 ≤ x__i, y__i ≤ n; x__i ≠ y__i).
Consider all the parts are numbered from 1 to n.
第一行包含两个整数 n 和 m(1≤n≤1000;0≤m≤2000)。第二行包含 n 个整数:v1,v2,…,vn(0≤vi≤105)。随后是 m 行,每行包含两个整数 xi 和 yi,表示一条连接第 xi 部分与第 yi 部分的绳子(1≤xi,yi≤n;xi=yi)。
假设所有部分编号从 1 到 n。
输出格式
Output the minimum total energy the child should spend to remove all n parts of the toy.
输出孩子移除该玩具全部 n 个部件所需消耗的最小总能量。
输入输出样例
输入#1
4 3 10 20 30 40 1 4 1 2 2 3
输出#1
40
输入#2
4 4 100 100 100 100 1 2 2 3 2 4 3 4
输出#2
400
输入#3
7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4
输出#3
160
说明/提示
One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20.
- Then, remove part 2, cost of the action is 10.
- Next, remove part 4, cost of the action is 10.
- At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts.
第一个样例中的一个最优操作序列如下:
- 首先,移除第 3 部分,该操作的代价为 20;
- 然后,移除第 2 部分,该操作的代价为 10;
- 接着,移除第 4 部分,该操作的代价为 10;
- 最后,移除第 1 部分,该操作的代价为 0。
因此,孩子总共消耗的能量为 20+10+10+0=40,这是最小值。
在第二个样例中,无论孩子以何种顺序移除各部分,都将消耗 400 的能量。
输入解题思路,AI测评打分。不知道怎么写?