codeforces 437C The Child and Toy

codeforces 437C The Child and Toy

大家好,又见面了,我是全栈君。

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 vi. The child spend vf1 + vf2 + … + vfk energy for removing part i where f1, f2, …, fk 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.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10000 ≤ m ≤ 2000). The second line contains n integers: v1, v2, …, vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ nxi ≠ yi).

Consider all the parts are numbered from 1 to n.

Output

Output the minimum total energy the child should spend to remove all n parts of the toy.

Sample test(s)
input
4 3
10 20 30 40
1 4
1 2
2 3

output
40

input
4 4
100 100 100 100
1 2
2 3
2 4
3 4

output
400

input
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

output
160

Note

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.

翻译

在儿童节这一天,我们的小朋友收到了来自Delayyy的礼物:一个玩具。

只是。小朋友实在是太淘气了。他迫不及待的要拆掉这个玩具。
这个玩具由n个部分和m条绳子组成。每条绳子连接着两个部分,而且不论什么两个部分至多由一条绳子直接相连。为了拆掉这个玩具,小朋友必须移除它的全部n个部分。每次他仅仅能移除一个部分。而且移除须要能量。

每个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+…+v[f[k]],当中f[1],f[2],…,f[k]是与i直接相连(且还未被移除)的部分的编号。
请帮助他找到移除n个部分所需的最小总能量。
Input
第一行包括两个整数n,m(1<=n<=10000;0<=m<=2000)。第二行包括n个整数v[1],v[2],…,v[n](0<=v[i]<=10^5)。接下来有m个行,每一行有两个整数x[i]和y[i],表示一条连接x[i]和y[i]的绳子(1<=x[i],y[i]<=n; x[i]不等于y[i])。
Output

输出所需的最小能量。

题解

有没有感觉看了这么长的题目非常累。事实上代码就这么短……骂人

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,m,w[1005];
long long ans=0;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&w[i]);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        ans+=min(w[x],w[y]);
    }
    printf("%lld",ans);
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116148.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • windows oracle rac集群搭建_linux集群管理工具

    windows oracle rac集群搭建_linux集群管理工具浅谈OracleRAC–集群管理软件GI今天周五,想想可以过周末,心情大好。一周中最喜欢过的就是周五晚上,最不喜欢过的是周日晚上和周一,看来我不是个热爱劳动的人啊。趁着现在心情愉悦,赶紧坐下来继续写我的博客吧。昨天的博客里,我介绍了什么是OracleRAC。还没有看过的同学可以回过头去参考一下。我们说从实现技术上来说OracleRAC是基于集群管理软件构建出的数据库。那么研究OracleRAC的基础则是要搞懂集群管理软件的原理。昨天的博客里我们介绍了现在甲骨文早已不再依托第三方集群

    2022年10月11日
    4
  • CAS底层原理(cas理论模型)

    一、什么是CASCAS的全称为Compare-And-Swap,它是一条CPU并发原语。它的功能是判断内存某个位置的值是否为预期值,如果是则更新为新的值,这个过程是原子的。CAS并发原语提现在Java语言中就是sun.miscUnSafe类中的各个方法。调用UnSafe类中的CAS方法,JVM会帮我实现CAS汇编指令.这是一种完全依赖于硬件功能,通过它实现了原子操作。再次强调,由于CA…

    2022年4月14日
    58
  • for循环中执行顺序_顺序结构选择结构循环结构

    for循环中执行顺序_顺序结构选择结构循环结构今天刷题碰到的一个坑,就是没有注意到for循环的每次判断条件导致的**,也就是for循环的第二句**,每次循环都会执行该判断条件。for循环的表达式一般如下:for(表达式1;表达式2;表达式3){表达式4;}执行的顺序为:第一次循环首先执行表达式1(一般为初始化语句,只执行一次),再执行表达式2(条件判断语句),判断表达式1是否符合表达式2的条件,如果符合,则执行表达式4,……

    2025年7月1日
    3
  • 26.学习Camera之——PDAF(相位对焦)的基本原理

    26.学习Camera之——PDAF(相位对焦)的基本原理在自动对焦的时候总是有一个困惑,知道图像是不清楚的,但是lens应该向前还是向后移动呢?总是要前后移动lens一下才知道,普通的反差法对焦就是这么做的,爬山嘛。PDAF的出现就是为了解决这个lens移动的问题,可以根据图像,预判lens运动的方向。PDAF最早运用在单反上,已经是非常成熟的技术了,原理如下图。左图为CCD在焦后的情况,右图为焦前。当CCD在焦后时,在线阵CCD1和CCD2上会发现聚焦点CCD1的在左,反之,则聚焦点CCD2的在左(图中红色标记的光线)。这种方法需要加.

    2025年9月24日
    5
  • webstorm激活码【2021最新】

    (webstorm激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlWKAWTQAJR5-eyJsaWNlbnNlSWQi…

    2022年3月22日
    48
  • redhat6.5安装oracle11g安装界面乱码

    redhat6.5安装oracle11g安装界面乱码说明:redhat6.5由于安装的是中文环境,安装执行./runInstaller安装出现以下乱码解决办法:LANG=en_US  ./runInstaller 安装时临时指定语言环境,再执行安装现在可以看到没乱码了!

    2022年7月25日
    13

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号