树链剖分裸题。

。。

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

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. vue - check-versions.js for chalk

    chalk:npm 官网 修改命令输出的文字颜色.粗细等....

  2. ColorSchemer Studio 2 破解

    软件介绍: ColorSchemer Studio 2 is a professional color matching application for anyone from hobbyists t ...

  3. vue-cli webpack 中全局引入 jquery

    1.安装 jquery npm install jquery --save-dev 2.修改 webpack.base.conf.js 方法一 首先加入: const webpack = requir ...

  4. Vue 进入/离开动画

    1.示例代码 (注:写到vue单文件中了) <template> <div> <button v-on:click="show = !show"> ...

  5. 设计模式:工厂方法模式(Python)

    来自:http://blog.csdn.net/ericzhong83/article/details/7604728 工厂方法模式(Factory Method Pattern): 定义了一个创建对 ...

  6. iOS编程 手动忽略clang编译器警告

    在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak.循环引用.不能运行之类的警告. 有代码洁癖的孩子们非常想消除他们, 今天就让我们来一次Fuck 警告.! 首先学会主要的语句 #pra ...

  7. kvaser leaf light v2 在Linux 下面的使用方法

    一.安装驱动 下载地址: https://www.kvaser.cn/developer-blog/build-install-signed-kvaser-driver-modules/  严格按照操 ...

  8. Yii2.0 下的 load() 方法的使用

    一 问题 最近在使用 Yii2.0,遇到一个 bug:在 /models/OrderDetail.php add() 方法中调用 load() 方法加载数据,却加载不了. public functio ...

  9. WPF中Auto与*的差别

    Auto 表示自己主动适应显示内容的宽度, 如自己主动适应文本的宽度,文本有多长,控件就显示多长. * 则表示按比例来分配宽度. <ColumnDefinition Width="3* ...

  10. (四)Maven构建多模块项目

    在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为domain(域模型层).dao(数据库访问层).service(业务逻辑层).web(表现层),这样分层之 ...