Codeforces The Child and Toy
The Child and Toy
time limit per test1 second
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
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
就是给你n个点,每个点有个权值,然后你要把这些点都删掉,删一个点的代价是与这个点相连的未被删除的点的权值之和。。。
洗澡的时候顺便贪心了一下,从大到小就好了
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
struct lpl{
int num;
long long val;
}node[maxn];
vector<int> point[maxn];
int n, m;
long long ans, ld[maxn];
bool flag[maxn];
inline void putit()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i) node[i].num = i, scanf("%lld", &node[i].val), ld[i] = node[i].val;
for(int a, b, i = 1; i <= m; ++i){
scanf("%d%d", &a, &b);
point[a].push_back(b); point[b].push_back(a);
}
}
inline bool cmp(lpl A, lpl B){return A.val > B.val;}
int main()
{
putit();
sort(node + 1, node + n + 1, cmp);
for(int i = 1; i <= n; ++i){
flag[node[i].num] = true;
for(int now, j = point[node[i].num].size() - 1; j >= 0; --j){
now = point[node[i].num][j]; if(flag[now]) continue;
ans += ld[now];
}
}
cout << ans;
return 0;
}
Codeforces The Child and Toy的更多相关文章
- Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces Round #250 Div. 2(C.The Child and Toy)
题目例如以下: C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input ...
- cf437C The Child and Toy
C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 437C The Child and Toy
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces Round #250 (Div. 2) C、The Child and Toy
注意此题,每一个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+...+v[f[k]],其中f[1],f[2],...,f[k]是与i直接相连(且还未被移除)的部 ...
- Codeforces #250 (Div. 2) C.The Child and Toy
之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小 ...
- The Child and Toy
Codeforces Round #250 (Div. 2) C:http://codeforces.com/problemset/problem/437/C 题意:给以一个无向图,每个点都有一点的权 ...
- CF(437C)The Child and Toy(馋)
意甲冠军:给定一个无向图,每个小点右键.操作被拉动所有点逐一将去,直到一个点的其余部分,在连边和点拉远了点,在该点右点的其余的费用.寻找所需要的最低成本的运营完全成本. 解法:贪心的思想,每次将剩余点 ...
随机推荐
- elasticsearch 基础 —— Jion父子关系
前言 由于ES6.X版本以后,每个索引下面只支持单一的类型(type),因此不再支持以下形式的父子关系: PUT /company { "mappings": { "br ...
- XMPP即时通讯协议使用(四)——Openfire服务器源码编译与添加消息记录保存
下载Openfire源码 下载地址:https://www.igniterealtime.org/downloads/index.jsp,当前最新版本为:4.2.3 Eclipse上部署Openfir ...
- regex - POSIX 1003.2 正则表达式
DESCRIPTION 正则表达式 (``RE''s), 在 POSIX 1003.2 中定义,包含两种类型:新式 REs (基本上指的是 egrep 使用的那些,1003.2 称其为 ``exten ...
- [react-native]react-native填坑笔记
填坑笔记 开始入坑RN,从最开始的学起难免有不少乱七八糟的问题,记录在这里. 1. 8081端口占用问题 按照官网教程搭建开发环境并按照下面代码运行时候有报错,显示8081端口的问题 react-na ...
- Vue-native绑定原生事件
首先介绍一下是什么意思: 意思就是当你给一个vue组件绑定事件时候,要加上native!如果是普通的html元素!就不需要 <div id = "app"> <m ...
- linux下载网页上的文件夹以及删除文件(stream)
wget -nd -r -l1 --no-parent http://www.cs.virginia.edu/stream/FTP/Code/ 注:-nd 不创建目录:-r 递归下载:-l1只下载当前 ...
- RBAC用户权限管理数据库设计的图文详解
RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,每一个角色拥有若干权限.这样,就构造成“用户-角色- ...
- 【串线篇】加谈数据库之连接join
主题:内连接.左连接(左外连接).右连接(右外连接) 建表语句: CREATE TABLE `a_table` ( `a_id` int(11) DEFAULT NULL, `a_name` va ...
- JSP和selevt 生命周期详解(JSP的生命周期和select很像,jsp底层就是一个selevt)
JSP: JSP的生命周期指从创建到销毁的整个过程.分为以下几个阶段: 1:编译阶段:servlet引擎编译servlet源文件,生成servlet类.当浏览器请求JSP页面时,JSP引擎会首先去检查 ...
- c++ ofstream使用方法
ofstream是从内存到硬盘,ifstream是从硬盘到内存,流缓冲即是内存空间. 插入器<< : 向流输出数据. cout << "test!" &l ...