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 ...
随机推荐
- SourceInsight工具增强——AStyle(代码格式化)、PC-Lint(静态检查)
Artistic Style(AStyle) AStyle是一款开源.高效.精简的代码格式化工具,适用于C.C++.C#.Java等.官方地址在:http://astyle.sourceforge.n ...
- Django 学习 (第四部)
1.Django请求的生命周期 首先是url---->路由系统 -> 试图函数(获取模板+数据=>渲染) -> 字符串返回给用户2.路由系统{建立路由关系urls.py (fu ...
- LINQ Group By操作(转载)
假设我们需要从两张表中统计出热门商圈,这两张表内容如下: 上表是所有政区,商圈中的餐饮个数,名为FoodDistrict 下表是所有政区,商圈中的SPA个数,名为SPADistrict 现在要把这两张 ...
- Dubbo与Zookeeper在Window上的安装与简单使用
一:Dubbo是什么?有什么用途?? 使用Dubbo可以将应用分布到多个服务器上,当有访问时,Dubbo有帮你管理自动将请求分配给合适得到服务器去执行,即建立多个生产者,建立多个消费者,自动匹配生产者 ...
- BZOJ3817 清华集训2014 Sum 类欧几里得
传送门 令\(\sqrt r = x\) 考虑将\(-1^{\lfloor d \sqrt r \rfloor}\)魔改一下 它等于\(1-2 \times (\lfloor dx \rfloor \ ...
- 数据库日志——mysql与Oracle的日志
一.MySQL 在数据同步中用的比较多的是MySQL的binlog 1.bin-log简介 它记录了所有的DDL和DML(除了数据查询语句,select与show不记录)语句,以事件形式记录,还包含语 ...
- 面试2——java基础2
11.MVC设计模型 mvc设计模型是一种使用model-view-controller(模型-视图-控制器)设计创建web应用程序的模式.是一种开发模式,好处是可以将界面和业务逻辑分离. model ...
- 【UFUN开发板评测】小巧而不失精致,简单而不失内涵——uFun开发板开箱爆照
关于uFun学习板--"满满的爱和正能量" uFun是由@张进东 张工组织发起的一个开源的学习板,设计初衷是为了帮助学生更好的理解电子知识和开发技巧,同时又能对学生毕业找工作有很明 ...
- Ubuntu16.04下安装破解secureCRT和secureFX的操作记录
本地电脑之前安装的是win10,疲于win10频繁的更新和各种兼容问题,果断放弃win10系统,安装了Ubuntu 16.04系统,现在微信.QQ.钉钉.WPS等都已支持linux版本,所以在Ubun ...
- tmux使用总结
ctrl+b +%:增加垂直分屏 ctlr+b +左右箭头: 在垂直分屏中移动 ctrl+b+c:新建窗口(不分屏) ctrl+b+数字键: 切换窗口 ctrl+b+d: 断开窗口 tmux a : ...