树链剖分裸题。

。。

又要扩栈又要输入挂还卡格式。。。。真无语

Tree

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1538    Accepted Submission(s): 261

Problem Description
You are given a tree (an acyclic undirected connected graph) with N nodes. The tree nodes are numbered from 1 to N



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.
 
Input
The first line of the input is T (1 ≤ T ≤ 20), which stands for the number of test cases you need to solve.



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)
 
Output
For each test case, print a line “Case #t:”(without quotes, t means the index of the test case) at the beginning.



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.
 
Sample Input
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
 
Sample Output
Case #1:
1 1 0 1
0 2 2
Case #2:
5 0 0 5
0 4 0
 
Source
 

posted on
2017-05-05 10:11 
lxjshuju 
阅读(...) 
评论(...) 
编辑 
收藏

HDOJ 5044 Tree的更多相关文章

  1. HDU 5044 Tree(树链剖分)

    HDU 5044 Tree field=problem&key=2014+ACM%2FICPC+Asia+Regional+Shanghai+Online&source=1&s ...

  2. hdoj 2682 Tree

    Tree Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. HDOJ 3516 Tree Construction

    四边形优化DP Tree Construction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. HDU 5044 Tree 树链剖分+区间标记

    Tree Problem Description You are given a tree (an acyclic undirected connected graph) with N nodes. ...

  5. HDOJ 2682 Tree(最小生成树prim算法)

    Tree Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  6. 树形DP+DFS序+树状数组 HDOJ 5293 Tree chain problem(树链问题)

    题目链接 题意: 有n个点的一棵树.其中树上有m条已知的链,每条链有一个权值.从中选出任意个不相交的链使得链的权值和最大. 思路: 树形DP.设dp[i]表示i的子树下的最优权值和,sum[i]表示不 ...

  7. HDU 5044 Tree --树链剖分

    题意:给一棵树,两种操作: ADD1: 给u-v路径上所有点加上值k, ADD2:给u-v路径上所有边加上k,初始值都为0,问最后每个点和每条边的值,输出. 解法:树链剖分可做,剖出来如果直接用线段树 ...

  8. HDU 5044 TREE

    题意:一棵树上两种操作,操作1,改变u到v的每一点的值增加k,操作2,改变u到v每一条边值增加k.最后结束时问,每一点和每一条边的值. 初始时,点和边的值都为0. 分析: 很显然要用树链剖分,将点和边 ...

  9. HDOJ 3516 Tree Construction 四边形优化dp

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意: 大概就是给你个下凸包的左侧,然后让你用平行于坐标轴的线段构造一棵树,并且这棵树的总曼哈顿 ...

随机推荐

  1. EL表达式中null和empty的区别

    下面通过一个例子看看看null和empty的区别,建立一个test.jsp文件,内容如下: <%@page pageEncoding="utf-8" %> name:$ ...

  2. kubelet分析

    kubelet是k8s中节点上运行的管理工具,它负责接受api-server发送的调度请求,在Node上创建管理pod,并且向api-server同步节点的状态.这篇文章主要讲讲kubelet组件如何 ...

  3. Unity3D 图形问题之怎样使用水?

     怎样使用水? 注意:本页所述内容仅仅适用于台式机编辑器模式. Unity 的标准资源和专业版标准资源包 (Standard Assets and Pro Standard Assets pack ...

  4. 火车票订票API 用PHP完成火车票订票流程

    本教程用来演示聚合数据-火车票订票接口的使用流程. 配置好PHP环境,PHP版本最好大于5.5 去聚合数据-火车票订票接口申请key:http://www.juhe.cn/docs/api/id/17 ...

  5. LoadRunner测试AJAX

    什么是AJAX? Ajax, shorthand for Asynchronous JavaScript and XML, is a web development technique for cre ...

  6. mac os x 安装adb

    http://stackoverflow.com/questions/31374085/installing-adb-on-mac-os-x Option 1 - Using Homebrew Thi ...

  7. iOS 物流信息时间轴

    代码地址如下:http://www.demodashi.com/demo/11958.html timelineLogistics 是模仿淘宝物流信息时间轴界面的自定义View 准备工作 引入Maso ...

  8. 安装JDK不当--找不到或无法加载主类 com.sun.tools.javac.Main

    问题描述:我的问题是在使用javac编译测试程序市,出现如下错误: 错误: 找不到或无法加载主类 com.sun.tools.javac.Main 解决办法:当出现这个错误时,百度之,结果很多人都是说 ...

  9. SVN学习(一)——SVN 检出文件步骤、图标显示及含义

    May, I come... 1. 创建一个目录用来存放检出得到的文件,例如MyCRM 2. 直接进入目录MyCRM,点右键 3. 可以看到检出得到的文件 此时文件图标上没有任何标识.可能你会想到通过 ...

  10. 使用caffe 的 python接口测试数据,选定GPU编号

    只需要在python脚本中添加两行代码: caffe.set_device(0) #使用第一块显卡 caffe.set_mode_gpu() #设为gpu模式 这样,就可以在默认显卡被占用(第一块显卡 ...