HDOJ 5044 Tree
树链剖分裸题。
。
。。
又要扩栈又要输入挂还卡格式。。。。真无语
Tree
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1538 Accepted Submission(s): 261
There are N - 1 edges numbered from 1 to N - 1.
Each node has a value and each edge has a value. The initial value is 0.
There are two kind of operation as follows:
● ADD1 u v k: for nodes on the path from u to v, the value of these nodes increase by k.
● ADD2 u v k: for edges on the path from u to v, the value of these edges increase by k.
After finished M operation on the tree, please output the value of each node and edge.
The first line of each case contains two integers N ,M (1 ≤ N, M ≤105),denoting the number of nodes and operations, respectively.
The next N - 1 lines, each lines contains two integers u, v(1 ≤ u, v ≤ N ), denote there is an edge between u,v and its initial value is 0.
For the next M line, contain instructions “ADD1 u v k” or “ADD2 u v k”. (1 ≤ u, v ≤ N, -105 ≤ k ≤ 105)
The second line contains N integer which means the value of each node.
The third line contains N - 1 integer which means the value of each edge according to the input order.
2
4 2
1 2
2 3
2 4
ADD1 1 4 1
ADD2 3 4 2
4 2
1 2
2 3
1 4
ADD1 1 4 5
ADD2 3 2 4
Case #1:
1 1 0 1
0 2 2
Case #2:
5 0 0 5
0 4 0
HDOJ 5044 Tree的更多相关文章
- HDU 5044 Tree(树链剖分)
HDU 5044 Tree field=problem&key=2014+ACM%2FICPC+Asia+Regional+Shanghai+Online&source=1&s ...
- hdoj 2682 Tree
Tree Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDOJ 3516 Tree Construction
四边形优化DP Tree Construction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- HDU 5044 Tree 树链剖分+区间标记
Tree Problem Description You are given a tree (an acyclic undirected connected graph) with N nodes. ...
- HDOJ 2682 Tree(最小生成树prim算法)
Tree Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 树形DP+DFS序+树状数组 HDOJ 5293 Tree chain problem(树链问题)
题目链接 题意: 有n个点的一棵树.其中树上有m条已知的链,每条链有一个权值.从中选出任意个不相交的链使得链的权值和最大. 思路: 树形DP.设dp[i]表示i的子树下的最优权值和,sum[i]表示不 ...
- HDU 5044 Tree --树链剖分
题意:给一棵树,两种操作: ADD1: 给u-v路径上所有点加上值k, ADD2:给u-v路径上所有边加上k,初始值都为0,问最后每个点和每条边的值,输出. 解法:树链剖分可做,剖出来如果直接用线段树 ...
- HDU 5044 TREE
题意:一棵树上两种操作,操作1,改变u到v的每一点的值增加k,操作2,改变u到v每一条边值增加k.最后结束时问,每一点和每一条边的值. 初始时,点和边的值都为0. 分析: 很显然要用树链剖分,将点和边 ...
- HDOJ 3516 Tree Construction 四边形优化dp
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意: 大概就是给你个下凸包的左侧,然后让你用平行于坐标轴的线段构造一棵树,并且这棵树的总曼哈顿 ...
随机推荐
- 对jsp中Url含中文字符的编码处理
有一段url="/app/index/index.jsp?userName='测试'":在传入到jsp页面后. 用 <% String userName=request.g ...
- 【千纸诗书】—— PHP/MySQL二手书网站后台开发之项目设计
前言:这个项目是毕设时候做的,我负责后台数据操作部分,已经很久了,这次回顾这部分,是为了复习PHP和MySQL的知识,正好现在在公司也负责的是后台管理系统的业务.第一篇[项目概况]附上毕业论文部分节选 ...
- infer 编译代码审查命令记录
infer -- xcodebuild -target <target name> -configuration <build configuration> -sdk ipho ...
- webpack入门学习总结
<h5概述</h5> webpack是当下最热门的前端资源模块化管理和打包工具.它可以将许多松散的模块按照依赖和规则打包成符合生产环境部署的前端资源.还可以将按需加载的模块进行代码分 ...
- 批量杀进程 ps awk grep
ps aux |grep lt-newindexclient |grep -v grep |awk grep -v 反向输出,即过滤掉带有grep的输出. xargs:传递参数
- Spring HibernateTemplate
HibernateTemplate利用模板设计模式,可将重复的opensession getcurrentsession工作省去,只将必要操作执行即可,其它的由spring来帮我们处理. < ...
- iOS学习笔记-自己动手写RESideMenu
代码地址如下:http://www.demodashi.com/demo/11683.html 很多app都实现了类似RESideMenu的效果,RESideMenu是Github上面一个stars数 ...
- mysql 5.6的安装
MySQL安装 yum install -y perl-Module-Install.noarch cd /usr/local/src wget http://mirrors.sohu.com/m ...
- AR路由器web界面每IP限速配置方法
一.做下载方向的限速:在 QOS>接口限速,选择“新建”“接口名称”选择内网接口“限速类型”选择IP限速(目的)“方向”选择流出“起始/目的ip”写内网的ip“类型”选择独占“承诺速率”为限速的 ...
- windows 2008 R2 x64安装oracle12c报INS-30131
问题描述:Window 2008 R2 x64安装Oracle12c报[INS-30131]执行安装程序验证所需的初始设置失败 解决方法:先在控制面板的“服务”,看SERVER服务是否启动,如果没有启 ...