【hdu4010】Query on The Trees

2014年12月11日2,57417
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

 

 

  • 尹一航2015年1月30日 下午1:42 回复

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

    #1  
    • 李雪欣2015年1月30日 下午2:49 回复

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

      #11
      • 尹一航2015年1月30日 下午4:36 回复

        orz

        #12
        • 魔法炮2015年4月9日 上午8:20 回复

          李雪欣?

          #13
          • 李雪欣2015年4月9日 上午8:22

            哈哈哈哈哈哈哈哈

            #14
          • 吴一凡2015年4月9日 下午4:26

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

            #14
          • 魔法炮2015年4月9日 下午6:33

            233333

            #14
        • 魔法炮2015年4月9日 上午8:22 回复

          一看就是GhobiruKKuribohG神犇又在卖萌

          #13
  • syk_____2015年4月8日 下午8:56 回复

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

    #2  
  • 吴钰晗2015年4月10日 下午2:08 回复

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

    #3  
  • 吴钰晗2015年4月10日 下午2:08 回复

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

    #4  
  • ssqqq2016年2月17日 下午6:11 回复

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

    #5  
    • hzwer2016年2月18日 上午12:10 回复
      admin

      就是把链的方向反转一下

      #51
      • ssqqq2016年2月18日 下午12:15 回复

        那么这个也是懒惰标记咯?即不访问不翻转,访问即下传翻转?

        #52