「hdu4010」Query on The Trees

2014年12月11日5,37617
Problem Description
We have met so many problems on the tree, so today we will have a query problem on a set of trees.
There are N nodes, each node will have a unique weight Wi. We will have four kinds of operations on it and you should solve them efficiently. Wish you have fun!

 

Input
There are multiple test cases in our dataset.
For each case, the first line contains only one integer N.(1 ≤ N ≤ 300000) The next N‐1 lines each contains two integers x, y which means there is an edge between them. It also means we will give you one tree initially.
The next line will contains N integers which means the weight Wi of each node. (0 ≤ Wi ≤ 3000)
The next line will contains an integer Q. (1 ≤ Q ≤ 300000) The next Q lines will start with an integer 1, 2, 3 or 4 means the kind of this operation.
1. Given two integer x, y, you should make a new edge between these two node x and y. So after this operation, two trees will be connected to a new one.
2. Given two integer x, y, you should find the tree in the tree set who contain node x, and you should make the node x be the root of this tree, and then you should cut the edge between node y and its parent. So after this operation, a tree will be separate into two parts.
3. Given three integer w, x, y, for the x, y and all nodes between the path from x to y, you should increase their weight by w.
4. Given two integer x, y, you should check the node weights on the path between x and y, and you should output the maximum weight on it.
Output
For each query you should output the correct answer of it. If you find this query is an illegal operation, you should output ‐1.
You should output a blank line after each test case.
Sample Input
5 1 2 2 4 2 5 1 3 1 2 3 4 5 6 4 2 3 2 1 2 4 2 3 1 3 5 3 2 1 4 4 1 4
Sample Output
3 -1 7

Hint

We define the illegal situation of different operations: In first operation: if node x and y belong to a same tree, we think it’s illegal. In second operation: if x = y or x and y not belong to a same tree, we think it’s illegal. In third operation: if x and y not belong to a same tree, we think it’s illegal. In fourth operation: if x and y not belong to a same tree, we think it’s illegal.

 

题解
LCT裸题。。。
再不复习很多东西就白学了TAT

 

 

avatar
5 Comment threads
12 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
ssqqqhzwer魔法炮李雪欣李雪欣 Recent comment authors
  Subscribe  
提醒
ssqqq

黄学长,这个rev数组是用来干嘛的?窝刚学lct..

吴钰晗

然而我看不懂splay。。怎么办

TigerTang

你是不是在常州一中训练过

吴钰晗

吴钰晗

您是?

吴钰晗

splay还写左旋右旋的我看完黄学长的代码觉得我弱爆了

syk_____

cut之前为什么要makeroot一次啊 感觉可以不用的

尹一航

为什么觉得这个link好奇怪,怎么不用维护y节点的信息呢?

李雪欣
李雪欣

y的fa是x不代表y和x在一个链,这个fa是所谓的path_parent

尹一航

orz

魔法炮

李雪欣?

李雪欣
李雪欣

哈哈哈哈哈哈哈哈

吴一凡

羡慕名字有妹子给起的现充…

魔法炮

233333

魔法炮

一看就是GhobiruKKuribohG神犇又在卖萌