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 ...
随机推荐
- Python脱产8期 Day03 2019/4/15
一 变量的命名规范 1.只能由 字母, 数字, _, 组成. 2. 不能以数字开头 3.避免与系统关键字重名:重名不会报错,但系统的功能就被自定义的功能屏蔽掉了(严重不建议这样来做) 4.以_开头的 ...
- POJ2387(dijkstra堆优化)
Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...
- 4.1《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)—目录结构
Unix风格的目录结构通常使用一个目录名列表并用正斜杠分隔来表示,这样我们可以结合ls命令: $ ls /Users/mhartl/ruby 或者 $ ls /usr/local/bin 正如图20, ...
- LOJ2541 PKUWC2018 猎人杀 期望、容斥、生成函数、分治
传送门 首先,每一次有一个猎人死亡之后\(\sum w\)会变化,计算起来很麻烦,所以考虑在某一个猎人死亡之后给其打上标记,仍然计算他的\(w\),只是如果打中了一个打上了标记的人就重新选择.这样对应 ...
- Unity3d之树木创建的参数设定
Unity3d之树木创建的参数设定 通常Unity3d创建树木经常会创建出很多奇葩的种类=_=,以下是创建出比较正常树木的基本参数 1:> 基本树干形状建立: 选择根建立分枝干设置分支干Di ...
- jQuery生成QRcode二维码
jQuery生成QRcode二维码示例 <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...
- pyenv+virtual 笔记
Pyenv + virtualEnv 设置 安装这两个组件是为了适应不同版本的python在同一个系统下的运行:例如现在最明显就是python2.7和python3.6的两个版本,很多库依旧是使用了P ...
- ABP+AdminLTE+Bootstrap Table权限管理系统第三节--abp分层体系,实体相关及ABP模块系统
返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 ABP模块系统 说了这么久,还没有详细说到abp框架,abp其实基于DDD(领域驱动设计)原则的细看分层如下: 再 ...
- ASPCMS_判断语句if标签的使用
这几天在仿个企业站,又用到了ASPCMS.这个CMS系统支持响应式模板——视访问设备而使用不同的模板,这样PC.手机都能兼顾. ▼官方给出的说明: 1.满足条件则显示 {if:条件语句} 显示内容 { ...
- JackSon学习笔记(一)
概述 Jackson框架是基于Java平台的一套数据处理工具,被称为“最好的Java Json解析器”. Jackson框架包含了3个核心库:streaming,databind,annotation ...