hdu 5242 Game(树链剖分,贪心¥)
Game
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1376 Accepted Submission(s): 449
One day he gets a new gal game named ''XX island''. There are n scenes in that game, and one scene will be transformed to different scenes by choosing different options while playing the game. All the scenes form a structure like a rooted tree such that the root is exactly the opening scene while leaves are all the ending scenes. Each scene has a value , and we use wi as the value of the i-th scene. Once Katsuragi entering some new scene, he will get the value of that scene. However, even if Katsuragi enters some scenes for more than once, he will get wi for only once.
For his outstanding ability in playing gal games, Katsuragi is able to play the game k times simultaneously. Now you are asked to calculate the maximum total value he will get by playing that game for k times.
For each test case, the first line contains two numbers n,k(1≤k≤n≤100000), denoting the total number of scenes and the maximum times for Katsuragi to play the game ''XX island''.
The second line contains n non-negative numbers, separated by space. The i-th number denotes the value of the i-th scene. It is guaranteed that all the values are less than or equal to 231−1.
In the following n−1 lines, each line contains two integers a,b(1≤a,b≤n), implying we can transform from the a-th scene to the b-th scene.
We assume the first scene(i.e., the scene with index one) to be the opening scene(i.e., the root of the tree).
5 2
4 3 2 1 1
1 2
1 5
2 3
2 4
5 3
4 3 2 1 1
1 2
1 5
2 3
2 4
Case #2: 11
hdu 5242 Game(树链剖分,贪心¥)的更多相关文章
- HDU 5242 利用树链剖分思想进行贪心
题目大意: 在给定带权值节点的树上从1开始不回头走到某个底端点后得到所有经过的点的权值后,这些点权值修改为0,到达底部后重新回到1,继续走,问走k次,最多能得到多少权值之和 这其实就是相当于每一次都走 ...
- hdu 5458 Stability(树链剖分+并查集)
Stability Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Total ...
- HDU 5044 (树链剖分+树状数组+点/边改查)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5044 题目大意:修改链上点,修改链上的边.查询所有点,查询所有边. 解题思路: 2014上海网赛的变 ...
- HDU 3966(树链剖分+点修改+点查询)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3966 题目大意:营地的分布成树型.每个营地都有一些人,每次修改修改一条链上的所有营地的人数,每次查询单 ...
- HDU 5458 Stability (树链剖分+并查集+set)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 给你n个点,m条边,q个操作,操作1是删边,操作2是问u到v之间的割边有多少条. 这题要倒着做才 ...
- HDU 5044 Tree --树链剖分
题意:给一棵树,两种操作: ADD1: 给u-v路径上所有点加上值k, ADD2:给u-v路径上所有边加上k,初始值都为0,问最后每个点和每条边的值,输出. 解法:树链剖分可做,剖出来如果直接用线段树 ...
- HDU - 3966-Aragorn' Story(树链剖分+线段树)
链接:https://vjudge.net/problem/HDU-3966 题意: Our protagonist is the handsome human prince Aragorn come ...
- HDU 3966 RE 树链剖分 线段树 Aragorn's Story
题意: 给出一棵树,每个顶点上有一个权值. 操作:选择一条路径,并将路径上所有的点的权值同时加或减某个数. 查询:某个点的当前权值 分析: 树链剖分完毕后,就是简单的线段树区间更新. 提交的时候注意要 ...
- Tree HDU - 6547 (树链剖分,线段树)
wls 有三棵树,树上每个节点都有一个值 ai,现在有 2 种操作: 将一条链上的所有节点的值开根号向下取整: 求一条链上值的和: 链的定义是两点之间的最短路. Input 第一行两个数 n, q 分 ...
- bzoj4811 [Ynoi2017]由乃的OJ 树链剖分+贪心+二进制
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4811 题解 我现在为什么都写一题,调一天啊,马上真的退役不花一分钱了. 考虑这道题的弱化版 N ...
随机推荐
- 洛谷 P3263 [JLOI2015]有意义的字符串
洛谷 首先,看到\((\frac{(b+\sqrt{d})}{2})^n\),很快能够想到一元二次方程的解\(\frac{-b\pm\sqrt{\Delta}}{2a}\). 所以可以推出,\(\fr ...
- 安装VS2013 2015 需要IE10浏览器 跳过的方法
安装VS2013 如果浏览器版本较旧的话会提示要求你更新到IE10版本,很麻烦,那么我们如何跳过呢? 复制下面代码粘贴到文本文档里,修改文本txt后缀为bat,右键管理员运行. @ECHO OFF ...
- Android studio 相关下载
Android studio http://www.androiddevtools.cn/ Oracle的VirtulBox https://www.virtualbox.org/wiki/Down ...
- SUBMIT RM07DOCS【MB51】 获取返回清单,抓取标准报表数据
*&---------------------------------------------------------------------* *& Report YT_SUBMIT ...
- Way to OpenSource
@1:Follow any instructions in the readme and make sure that you can configure and run the project on ...
- etl接口测试总结
刚做完一个项目接触到了etl接口,趁还热乎做个总结. etl接口功能测试点总结:1.数据量的检查:目标表与源表数据量是否一致2.字段正确性:拉取源表字段是否为目标表所需要字段(会出现拉错字段情况)3. ...
- Python基础(12)_python模块之sys模块、logging模块、序列化json模块、pickle模块、shelve模块
5.sys模块 sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0) sys.version 获取Python解释程序的版本信息 ...
- maven 项目打包时无法解析读取properties文件
在做项目时遇见一个问题,无法解析properties文件的 内容 异常为 Could not resolve placeholder ......... 在此之前均有做相关的 配置 但是从未出现过如上 ...
- Rabbitmq消费失败死信队列
Rabbitmq 重消费处理 一 处理流程图: 业务交换机:正常接收发送者,发送过来的消息,交换机类型topic AE交换机: 当业务交换机无法根据指定的routingkey去路由到队列的时候,会全部 ...
- 【leetcode刷题笔记】Excel Sheet Column Number
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...