HDOJ 5044 Tree
2024-08-25 03:14:16
树链剖分裸题。
。
。。
又要扩栈又要输入挂还卡格式。。。。真无语
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.
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)
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.
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
最新文章
- Cocos2dx
- Apache Shiro系列教程之二:十分钟上手Shiro
- nyoj 115 城市平乱 dijkstra最短路
- 20160805_笔记本_CentOS6.4x64分区
- Delphi 中的全局快捷键+给指定窗体发送按键
- 面试前的准备---C#知识点回顾----02
- jrebel的安装配置
- MYSQL中的多类型查询及高级查询操作
- CSS选择器 - 性能的探究及提升
- Java中数据类型及其之间的转换(转)
- BZOJ:4333: JSOI2012 智者的考验
- Shell脚本 自动部署 SpringBoot 应用
- apache_php_mysql
- java发送http get请求的两种方式
- Java实现猜数字,附带提示功能。
- Spring的aop操作
- Spring Boot 揭秘与实战(二) 数据存储篇 - JPA整合
- R语言中常用包(二)
- 定时登录下载sftp服务器上的某些有规则的文件
- 【C#】Queue的简单试用
热门文章
- nginx监听相同端口,根据域名请求不同的server
- [Functional Programming] Pull Many Random Numbers in a Single State ADT Transaction
- perl学习笔记——哈希
- 关于POI 中单元格背景色设置(转)
- 【C#】重载重写重构
- Atitit  OOCSS vs bem
- Atitit.js跨域解决方案attilax大总结 后台java php c#.net的CORS支持
- Python内置函数之len()
- 使用wget工具抓取网页和图片 成功尝试
- python简单网页服务器示例