Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)

别再只盯着FIFO深度了!Xilinx AXI Stream FIFO的TDATA、TUSER信号实战配置指南 本文深入解析Xilinx AXI Stream FIFO中TDATA与TUSER信号的高级应用,提供视频处理和数据流传输系统中的实战配置指南。通过详细讲解TUSER、TLAST等辅助信号的功能与配置方法,帮助工程师优化复杂系统的设计,提升数据处理效率与可靠性。 阅读详情

C. The Child and Toy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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.




一个礼物由n部分及m条绳子组成,每次拆掉一个部分有代价v,问你最小代价是多少。


看似麻烦的题,往往代码都短,每次都选出小的加起来就好了。。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int maxn = 1005;
int n, m, v[maxn];
int main(int argc, char const *argv[])
{
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
		cin >> v[i];
	int ans = 0, x, y;
	while(m--) {
		cin >> x >> y;
		ans += min(v[x], v[y]);
	}
	cout << ans << endl;
	return 0;
}


2.4G跳频算法 2.4G切信道算法 (简例示意nRF52832) 2.4G跳频算法 nRF52832示例 2.4G自适应信道算法 阅读详情

相关推荐

线性代数笔记【空间曲面】

二次曲面 曲面可以看成是一个动点或一条动曲线按照一定条件或规律运动产生的轨迹 曲面的方程即是该动点的坐标所满足的方程 空间解析几何中,一般会涉及到由曲面写方程和由方程看曲面两种类型问题 曲面与曲面方程 球面方程 球面:空间内与定点的距离等于定长的点的集合 这一定点叫球心,定长叫半径 标准方程 (x−x0)2+(y−y0)2+(z−z0)2=r2(x-x_0)^2+(y-y_0)^2+(z-z_0)^2=r^2(x−x0​)2+(y−y0​)2+(z−z0​)2=r2 球心P0(x0,y0,z0)P_0(

qq_40500005的博客 3246

Codeforces Round #250 (Div. 1) A. The Child and Toy

A. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

flyljg的专栏 804

AGV舵轮选型实战:从核心参数到精准计算的完整指南

本文提供了一份详尽的AGV舵轮选型实战指南,强调从经验决策转向数据驱动。文章系统讲解了如何将工况需求转化为核心参数,并通过牵引力、扭矩、功率等关键计算步骤,指导工程师完成精准选型,避免因选型不当导致的运行故障与效率低下。

醉三国 495

Children's Day

   Today is Childrens Day. What gift will I give children.   When we cheer this day , we are sad for our old now. Treasuring time is important for us. When we were chileren,we hoped that we could gro

【猩猩的专栏】 1362

Synares病毒实战:如何手动清除C盘隐藏的Synaptics.exe(附资源修复脚本)

本文详细介绍了Synares感染型病毒的手动清除方法,该病毒伪装成Synaptics触摸板驱动,感染EXE和XLSX文件。文章提供了从病毒行为分析、母体清除到被感染文件修复的全流程指南,并附有实用的资源修复脚本和防御加固方案,帮助用户彻底清除这一顽固病毒。

lg888的博客 2345

网络管理与维护综合实训2:基于AD证书服务构建企业内部HTTPS安全访问体系

本实训项目通过在Windows Server 2022环境下搭建AD域、DNS服务和Web服务器,实现安全的企业网站访问。主要内容包括:在两台服务器上安装操作系统并配置网络;在S1服务器上部署活动目录域、证书服务和Web服务;创建两个网站(HTTP和HTTPS);配置DNS记录和SSL证书;设置防火墙规则限制HTTP访问而允许HTTPS访问。通过实践掌握了AD证书管理、DNS配置、Web服务器设置及防火墙规则配置等关键技能,为网站管理工作奠定了基础,同时认识到证书管理在Web安全中的重要性。

深耕计算机专业知识与技术。 997

Codeforces Round #250 (Div. 2) C. The Child and Toy 详解

output standard output 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

__ElemenT 1504

2026 年 3 月青少年软编等考 C/C++ 三级测试题解析

摘要 本文包含三部分内容: 单选题(10题):考察C++基础语法和数据结构知识,涉及vector、栈、队列的操作和特性。 判断题(10题):测试对动态数组、栈、队列、字符串操作的理解,包括内存管理、访问方式和函数返回值等。 编程题(1题):模拟火车站售票窗口排队场景,要求根据输入输出各窗口的排队情况,重点考查队列的实际应用和边界条件处理。 答案解析详细,涵盖常见编程考点,适合检验基础知识的掌握程度。

发布少儿编程考级的真题和优秀竞赛题解析,以及一些讲义。 251

CodeForces - 437C The Child and Toy (贪心)

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 ofnparts andmropes...

YOONGI 455

YOLO26原创自研: 魔改Bottleneck,具备多尺度和特征通道融合的结构

魔改Bottleneck,具备多尺度和特征通道融合的结构,该模型在检测准确性方面都取得了良好的效果,尤其在缺陷检测方向。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 317

5.3-集群电源模式解析

DSU-120 DynamIQ™集群支持9种电源模式,包括正常运行(ON)、完全断电(OFF)、三种数据保持模式(FUNC_RET、FULL_RET、MEM_RET)、两种调试模拟模式(OFF_EMU、MEM_RET_EMU),以及系统恢复模式(WARM_RST、DBG_RECOV)。这些模式通过智能管理电源状态,在保持数据完整性的同时实现功耗优化,并为系统调试和故障恢复提供支持。不同模式在RAM保持、逻辑断电和调试能力方面各有侧重,满足从正常运行到深度调试等不同场景需求。

baron-周贺贺-代码改变世界ctw 117

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 standard input output standard output On Children's Day, the child

Sun_tester的专栏 1801

双端之Nginx+Php结合PostgreSQL搭建Wordpress

制作的 PG4WP 分支版本,它与所有版本的 WordPress 兼容,解决了原版的一些问题。参数,确保 PostgreSQL 正在监听默认端口(通常是 5432),或者你自定义的端口。:PG4WP 插件存在缺陷和不完整的功能,可能与最新版本的 WordPress 不兼容。的插件,它允许 WordPress 使用 PostgreSQL 数据库。,如果看到 Nginx 的默认欢迎页面,说明 Nginx 已正确安装。,如果看到 Nginx 的默认欢迎页面,说明 Nginx 已正确安装。

宇宙第一小趴菜的博客 1891

**Codeforces Round #250 (Div. 2) C. The Child and Toy ACM解题报告(贪心难题)

今天是惨遭吊打,和学长做去年的儿童节专场,只做出来A题,B题直接暴力以为会超时,dp了半天过不了,C题贪心贪错了。。。 这题的大意是有n个部件,要把他们全部破坏,破坏i就需要与i相连的那些部件的能量,比如j,k与i相连,破坏i就需要vj+vk的能量,求全部破坏需要多少能量。 我也是太年轻,直接按照每个部件拆除所需能量升序排序,然后拆能量需要最小的。 这个方法的错误在于,也许有几次拆的时候,消

Miracle_ma的专栏 769

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Codeforces Round #250 Div1A Div2C 437C The Child and Toy 贪心

这道题我在考场上并不是自己想出来的,是在别人帮助下搞懂的。

KuribohG 1016

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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 standard input output standard output On Children's Day, the child got a toy

守护生命的绿荷的专栏 415

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Codeforces Round #250 (Div. 2)C. The Child and Toy(贪心)

传送门 Description 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 ofnparts andmropes. ...

weixin_30466039的博客 131

Codeforces 437C 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

XDU_PYL的博客 589

CF 437C The Child and Toy

http://codeforces.com/problemset/problem/437/C time limit per test 1 second memory limit per test 256 megabytes input: standard input output: standard output Description On Children’s Day, t...

tangzhide123yy的博客 323

Codeforces 437C The Child and Toy 简单图论贪心

C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

J. Cole 691

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

eazo的博客 408

H - The Child and Toy-CodeForces 437C-水题

这题看懂了直接 输出一条边中比较小的那个点的权值即可。。。当时没想到,一股脑就当成图去贪心了,所以复杂多了   #include #include #include #include #include #include #include using namespace std; // 邻接表vector实现 struct node { int val; int

缺氧 786

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/problem/A Description On Children's Day, the child got a toy from Delayyy as a prese...

weixin_34220834的博客 149

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2041

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1749

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711
上一篇: Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)
下一篇: POJ1195 Mobile phones(树状数组)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值