2014鞍山网络预选赛1006(LCT模板题)hdu5002
来源:互联网 发布:西安交大网络 编辑:程序博客网 时间:2024/04/25 17:56
Tree
Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 41 Accepted Submission(s): 10
Problem Description
You are given a tree with N nodes which are numbered by integers 1..N. Each node is associated with an integer as the weight.
Your task is to deal with M operations of 4 types:
1.Delete an edge (x, y) from the tree, and then add a new edge (a, b). We ensure that it still constitutes a tree after adding the new edge.
2.Given two nodes a and b in the tree, change the weights of all the nodes on the path connecting node a and b (including node a and b) to a particular value x.
3.Given two nodes a and b in the tree, increase the weights of all the nodes on the path connecting node a and b (including node a and b) by a particular value d.
4.Given two nodes a and b in the tree, compute the second largest weight on the path connecting node a and b (including node a and b), and the number of times this weight occurs on the path. Note that here we need the strict second largest weight. For instance, the strict second largest weight of {3, 5, 2, 5, 3} is 3.
Your task is to deal with M operations of 4 types:
1.Delete an edge (x, y) from the tree, and then add a new edge (a, b). We ensure that it still constitutes a tree after adding the new edge.
2.Given two nodes a and b in the tree, change the weights of all the nodes on the path connecting node a and b (including node a and b) to a particular value x.
3.Given two nodes a and b in the tree, increase the weights of all the nodes on the path connecting node a and b (including node a and b) by a particular value d.
4.Given two nodes a and b in the tree, compute the second largest weight on the path connecting node a and b (including node a and b), and the number of times this weight occurs on the path. Note that here we need the strict second largest weight. For instance, the strict second largest weight of {3, 5, 2, 5, 3} is 3.
Input
The first line contains an integer T (T<=3), which means there are T test cases in the input.
For each test case, the first line contains two integers N and M (N, M<=10^5). The second line contains N integers, and the i-th integer is the weight of the i-th node in the tree (their absolute values are not larger than 10^4).
In next N-1 lines, there are two integers a and b (1<=a, b<=N), which means there exists an edge connecting node a and b.
The next M lines describe the operations you have to deal with. In each line the first integer is c (1<=c<=4), which indicates the type of operation.
If c = 1, there are four integers x, y, a, b (1<= x, y, a, b <=N) after c.
If c = 2, there are three integers a, b, x (1<= a, b<=N, |x|<=10^4) after c.
If c = 3, there are three integers a, b, d (1<= a, b<=N, |d|<=10^4) after c.
If c = 4 (it is a query operation), there are two integers a, b (1<= a, b<=N) after c.
All these parameters have the same meaning as described in problem description.
For each test case, the first line contains two integers N and M (N, M<=10^5). The second line contains N integers, and the i-th integer is the weight of the i-th node in the tree (their absolute values are not larger than 10^4).
In next N-1 lines, there are two integers a and b (1<=a, b<=N), which means there exists an edge connecting node a and b.
The next M lines describe the operations you have to deal with. In each line the first integer is c (1<=c<=4), which indicates the type of operation.
If c = 1, there are four integers x, y, a, b (1<= x, y, a, b <=N) after c.
If c = 2, there are three integers a, b, x (1<= a, b<=N, |x|<=10^4) after c.
If c = 3, there are three integers a, b, d (1<= a, b<=N, |d|<=10^4) after c.
If c = 4 (it is a query operation), there are two integers a, b (1<= a, b<=N) after c.
All these parameters have the same meaning as described in problem description.
Output
For each test case, first output "Case #x:"" (x means case ID) in a separate line.
For each query operation, output two values: the second largest weight and the number of times it occurs. If the weights of nodes on that path are all the same, just output "ALL SAME" (without quotes).
For each query operation, output two values: the second largest weight and the number of times it occurs. If the weights of nodes on that path are all the same, just output "ALL SAME" (without quotes).
Sample Input
23 21 1 21 21 34 1 24 2 37 75 3 2 1 7 3 61 21 33 43 54 64 74 2 63 4 5 -14 5 71 3 4 2 44 3 62 3 6 54 3 6
Sample Output
Case #1:ALL SAME1 2Case #2:3 21 13 2ALL SAME
题意:RT
思路:LCT模板题,有点要注意的是向下延迟更新的时候要先更新将一条链加一个数,再更新替换成一个数
比赛的时候就是因为把这两个操作写反了导致交了10次才过,也是醉到不行~
0 0
- 2014鞍山网络预选赛1006(LCT模板题)hdu5002
- 2014鞍山网络预选赛1004(贪心)hdu5000
- 2014鞍山网络预选赛1005(概率DP)hdu5001
- 2014鞍山网络预选赛1010(缩点+高斯消元)hdu5006
- hdu5002:Tree (LCT)
- 2014上海网络预选赛1011(LCT)HDU5052
- hdu5002 LCT
- HDU5002--Tree(LCT)
- LCT - hdu5002 Tree
- LCT link-cut tree Hdu 5002 Tree 2014鞍山网络赛
- 2014北京网络预选赛1006(贪心)HDU5037
- 2014牡丹江网络预选赛E题(线段树)zoj3813
- 2014牡丹江网络预选赛D题(状压DP)zoj3812
- 2014牡丹江网络预选赛B题(找规律)zoj3810
- 2014网络赛 鞍山赛区
- LCT(模板题)BZOJ2049
- LCT模板题
- 2014牡丹江网络预选赛I题(字符串hash+简单DP)zoj3817
- opencv实现边缘检测
- ASP.NET中应用Excel:(5)保存
- extern两种使用
- ASP.NET中应用Excel:(6)在服务器端生成HTML表格
- 在ASP.NET中应用Excel:(7)表格尺寸的计算
- 2014鞍山网络预选赛1006(LCT模板题)hdu5002
- 数组中出现的逆序对
- 开关电源设计入门
- 在ASP.NET中应用Excel:(8)为HTML表格增加编辑功能
- Nginx服务器的基本模块
- poj 1042 Gone Fishing(DP)
- 【交互设计】交互设计职能介绍
- 转:Python的sort()
- json-lib之jsonConfig详细使用