The Child and Toy

CodeForces - 437C

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 ≤ 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.

Examples

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.

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
*/

最新文章

  1. 【bzoj1941】 Sdoi2010—Hide and Seek
  2. 100天后 - 100-days-later
  3. UVa 101 - The Blocks Problem(积木问题,指令操作)
  4. 【ASP.Net MVC】在AspNet Mvc使用Ajax
  5. HDU 1847 (博弈 找规律) Good Luck in CET-4 Everybody!
  6. [开发环境] Ubuntu12.04 Telnet服务设置
  7. 关于vim打开中文文件出现乱码问题
  8. HDU 3217 Health(状压DP)
  9. 【高德地图API】一句话搞定webmap(一)——轻地图组件
  10. gbdt的面试要点总结-上篇
  11. 【深度学习系列】用PaddlePaddle和Tensorflow实现GoogLeNet InceptionV2/V3/V4
  12. Linux下I/O多路转接之epoll(绝对经典)
  13. 最优秀的网络框架retrofit
  14. 判断本机ip是电信还是网通
  15. LoRa网关/RAK831
  16. eclipse jee使用
  17. Java创建文件
  18. Javascript异步编程之setTimeout与setInterval详解分析(一)
  19. &lt;context:component-scan&gt;自动扫描
  20. Ethereum 源码分析之框架

热门文章

  1. 作业二/Git的安装以及使用
  2. AMD和CMD规范
  3. 关于ELK
  4. GIT 分支管理:多人协作
  5. Unity报错 GameObject is already being activated or deactivated
  6. CF1060E Sergey and Subways 假的点分治
  7. International Programming Retreat Day(2018.11.17)
  8. hibernate 解决 java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.xxx 这类的问题
  9. 扩展ASP.NET Identity使用Int做主键
  10. iOS APP 中H5视频默认全屏播放问题解决