Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
2015-10-28 12:59
405 查看
A. The Child and Toy
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/438/problem/ADescription
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.
[b]Input[/b]
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.
[b]Output[/b]
Output the minimum total energy the child should spend to remove all n parts of the toy.
[b]Sample Input[/b]
4 3
10 20 30 40
1 4
1 2
2 3
[b]Sample Output[/b]
40
HINT
[b]题意[/b]
给你一个图,然后让你删除所有边,每条边删除的代价是这条边两边点权的最小值
然后问你花费多少
[b]题解:[/b]
跑一遍就好了,和删边顺序无关,所以随便跑啦
[b]代码[/b]
#include<iostream> #include<stdio.h> using namespace std; int a[1005]; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&a[i]); long long ans = 0; for(int i=1;i<=m;i++) { int x,y;scanf("%d%d",&x,&y); ans += min(a[x],a[y]); } printf("%lld\n",ans); }
相关文章推荐
- Java之Timer
- Heartbeat+DRBD+mysql高可用方案
- [leetcode] 55. Jump Game 解题报告
- 关于Foreach是如何实现的问题
- NOIP2014飞扬的小鸟
- http://codeforces.com/contest/34
- LeetCode 108: Convert Sorted Array to Binary Search Tree
- Understanding Linux /proc/cpuinfo
- 常用知识
- linux程序包管理之源码编译安装
- LeetCode:Search for a Range
- LM(Levenberg-Marquard)算法的实现
- webWMS开发过程记录(二)- WMS是什么
- 相互激励
- hihoCoder #1197 Give My Text Back
- block的一点知识
- myeclipse集成maven问题解决
- SVN使用小结
- /proc/mtd 各参数的含义 -- linux内核
- 爱你.一万年>>数据库基础