codeforces437C
The Child and Toy
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 ≤ 1000; 0 ≤ 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 ≤ n; xi ≠ 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.
Examples
4 3
10 20 30 40
1 4
1 2
2 3
40
4 4
100 100 100 100
1 2
2 3
2 4
3 4
400
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
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.
sol:容易发现删去一个点等于删掉所有与这个点相连的边,考虑每条边的贡献,比如边<a,b>,肯定取a,b中花费小的更优
Ps:代码极短
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,Cost[N];
#define Pic Picture
int main()
{
int i,ans=;
R(n); R(m);
for(i=;i<=n;i++) R(Cost[i]);
for(i=;i<=m;i++) ans+=min(Cost[read()],Cost[read()]);
Wl(ans);
return ;
}
/*
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
*/
codeforces437C的更多相关文章
- CodeForces-437C(贪心)
链接: https://vjudge.net/problem/CodeForces-437C 题意: On Children's Day, the child got a toy from Delay ...
随机推荐
- django_redis作为 session backend 使用配置
Django 默认可以使用任何 cache backend 作为 session backend, 将 django-redis 作为 session 储存后端不用安装任何额外的 backend # ...
- linux 用xshell工具远程登录
1.设置linux,获取ip,登录名.密码 2.xshell登录
- es3的语法来模拟es5的bind方法
// 简单版 Function.prototype.bind = function(context) { var self = this; return function() { self.apply ...
- TravelPort官方API解读
TravelPort Ping通使用教程 Unit1 Lesson 1: 标签(空格分隔): 完成第1单元的三个课程后,您可以使用Travelport Universal API来提出服务请求并了解响 ...
- OSC Source Code Innovation Salon(2018.10.20)
时间:2018.10.20地点:北京 朝阳 浦项中心B座2层
- CSV文件解析
CSV(逗号分隔值文件格式) 逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文本形式存储表格数据(数字和 ...
- RabbmitMQ-组成及简单使用
什么是MQ? MQ全程Message Queue,消息队列(MQ)是一种应用程序对应用程序的通信方法.MQ是消费者-生产者模型的典型代表.一端往消息队列中不断写消息而另一端则可以读取队列中的消息. R ...
- IOC框架之 Unity 入门
十年河东,十年河西,莫欺少年穷 学无止境,精益求精 Unity是什么? Unity是patterns & practices团队开发的一个轻量级.可扩展的依赖注入容器,具有如下的特性: 1. ...
- 浅谈CDQ分治与偏序问题
初识CDQ分治 CDQ分治是一个好东西,一直听着dalao们说所以就去学了下. CDQ分治是我们处理各类问题的重要武器.它的优势在于可以顶替复杂的高级数据结构,而且常数比较小:缺点在于必须离线操作. ...
- Excel 中批量处理数据(改成 json 格式)
如下excel: 需要处理成下面的效果: 方法: 在 C2 中输入公式: ="{"""&"code"&"" ...