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裸题
妈蛋 题看错了,以为操作2就是断掉x,y之间的边
对着黄学长的代码改了好久才发现这个问题
草草草草草草草草草草草草草草草草草草草草

hdu4010 Query On The Trees的更多相关文章

  1. HDU4010 Query on The Trees (LCT动态树)

    Query on The Trees Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Othe ...

  2. HDU4010 Query on The Trees(LCT)

    人生的第一道动态树,为了弄懂它的大致原理,需要具备一些前置技能,如Splay树,树链剖分的一些概念.在这里写下一些看各种论文时候的心得,下面的代码是拷贝的CLJ的模板,别人写的模板比较可靠也方便自己学 ...

  3. 动态树(LCT):HDU 4010 Query on The Trees

    Query on The Trees Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Othe ...

  4. HDOJ 4010 Query on The Trees LCT

    LCT: 分割.合并子树,路径上全部点的点权添加一个值,查询路径上点权的最大值 Query on The Trees Time Limit: 10000/5000 MS (Java/Others)   ...

  5. 【HDU4010】【LCT】Query on The Trees

    Problem Description We have met so many problems on the tree, so today we will have a query problem ...

  6. 【hdu4010】 Query on The Trees

    http://acm.hdu.edu.cn/showproblem.php?pid=4010 (题目链接) 题意 link cut tree板子 Solution link cut tree 细节 注 ...

  7. HDU 4010 Query on The Trees

    Problem Description We have met so many problems on the tree, so today we will have a query problem ...

  8. HDU 4010 Query on The Trees(动态树LCT)

    Problem Description We have met so many problems on the tree, so today we will have a query problem ...

  9. HDU 4010.Query on The Trees 解题报告

    题意: 给出一颗树,有4种操作: 1.如果x和y不在同一棵树上则在xy连边 2.如果x和y在同一棵树上并且x!=y则把x换为树根并把y和y的父亲分离 3.如果x和y在同一棵树上则x到y的路径上所有的点 ...

随机推荐

  1. websocket以及自定义协议编程一些总结

    以下仅供自己翻阅,因为时间久了会忘2.发送缓冲区主要是为了处理发送前一些小内容,可以自己控制flush,或者write的不是那么频繁因为没必要.至于大内容就没必要了.3.其实tcp以上的通信协议也好, ...

  2. Hash索引和BTree索引区别

    (1)Hash 索引仅仅能满足"=","IN"和"<=>"查询,不能使用范围查询. 由于 Hash 索引比较的是进行 Hash ...

  3. phpcms get标签说明

    {pc:get sql="SELECT * FROM phpcms_member" cache="3600" page="$page" db ...

  4. Laravel框架——增删改查

    增: //save返回true false $res = new member(); res->username = 'a'; $res->password = 'b'; dd($res- ...

  5. Unity3d shader内置矩阵

    内置矩阵 支持的矩阵(float4x4):UNITY_MATRIX_MVP        当前模型视图投影矩阵UNITY_MATRIX_MV           当前模型视图矩阵UNITY_MATRI ...

  6. 转:SSDB:快速取代redis的nosql

    原文来自于:http://hao.jobbole.com/ssdb%EF%BC%9A%E5%BF%AB%E9%80%9F%E5%8F%96%E4%BB%A3redis%E7%9A%84nosql/ S ...

  7. 转:PHP开发者应了解的24个库

    原文来自于:http://blog.jobbole.com/54201/ 作为一个PHP开发者,现在是一个令人激动的时刻.每天有许许多多有用的库分发出来,在Github上很容易发现和使用这些库.下面是 ...

  8. NYOJ 540

    为了给学弟学妹讲课,我水了一道题…… import java.util.Arrays; import java.util.Scanner; public class NYOJ540 { public ...

  9. Arbitrage

    Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit o ...

  10. 工程师必知ZigBee技术问答精华汇总

    本文是关于ZigBee技术的一些基础知识.行业应用方面的精华汇总.希望通过本文的分析,能让大家对ZigBee技术的起源.发展.特点.前景及其在通信网络中的相关应用有全面直观的了解. 1.基础知识篇 Q ...