树链剖分裸题。

。。

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

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. 字典对象的 Pythonic 用法(上篇:转载)

    转载:https://mp.weixin.qq.com/s?timestamp=1498528588&src=3&ver=1&signature=DfFeOFPXy44ObCM ...

  2. Java笔记7:最简单的网络请求Demo

    一.服务器端 1 新建一个工程,建立一个名为MyRequest的工程. 2 FileàProject StructureàModulesà点击最右侧的“+”àLibraryàJava 找到Tomcat ...

  3. 转:解决 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 错误

    Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN ...

  4. java压缩 GZIP进行简单压缩,ZIP进行多文件保存

    java压缩  GZIP进行简单压缩,ZIP进行多文件保存 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlhbmdydWkxOTg4/font/5a6 ...

  5. DevExpress 15.1.sln

    Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio VisualStudioVersion = 14 ...

  6. Splunk 会议回想: 大数据的关键是机器学习

    作者 Jonathan Allen ,译者 张晓鹏 Splunk的用户大会已经接近尾声.三天时间的会议里,共进行了160多个主题研讨.涵盖了从安全.运营到商业智能.甚至包含物联网,会议中一遍又一遍出现 ...

  7. 原生 javascript 基础回顾

    (1)打开新窗口 语法: window.open([URL], [窗口名称], [参数字符串]) 参数说明: URL:可选参数,在窗口中要显示网页的网址或路径.如果省略这个参数,或者它的值是空 字符串 ...

  8. Ubuntu——修正LibreOffice中文乱码以及eclipse提示框颜色

    刚进ubuntu的时候就老遇到用libreoffice打开某些文档时出现一堆叠在一起的乱码.以及最開始使用eclipse编辑时,鼠标放到一个变量或者函数时 弹出来一黑框框-看的难受的.... 这里记录 ...

  9. ps -ef/ps -aux 查看正在活动的进程

    ps -ef 查看正在活动的进程 ps -ef |grep abc 查看含有"abc"的活动进程 ps -ef |grep -v abc 查看不含abc的活动进程 1)ps a 显 ...

  10. 基于环信的仿QQ即时通讯的简单实现

    代码地址如下:http://www.demodashi.com/demo/11645.html 我的博客地址 之前一直想实现聊天的功能,但是感觉有点困难,今天看了环信的API,就利用下午的时间动手试了 ...