poj3237 Tree】的更多相关文章

POJ3237 Tree 树链剖分 边权 传送门:http://poj.org/problem?id=3237 题意: n个点的,n-1条边 修改单边边权 将a->b的边权取反 查询a->b边权最大值 题解: 修改边权就查询点的深度大的点,用大的点去存这条边的边权,其余的就和点权的是一样的了 取反操作用线段树维护,区间最大值取反就是区间最小值,区间最小值取反就是区间最大值 所以维护两颗线段树即可,lazy标记表示覆盖单边的边权 代码: #include <set> #include…
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ3237 题意概括 Description 给你由N个结点组成的树.树的节点被编号为1到N,边被编号为1到N-1.每一条边有一个权值.然后你要在树上执行一系列指令.指令可以是如下三种之一: CHANGE i v:将第i条边的权值改成v. NEGATE a b:将点a到点b路径上所有边的权值变成其相反数. QUERY a b:找出点a到点b路径上各边的最大权值. Input多组数据,数据为T<=20,对…
关于边剖 之前做的大多是点剖,其实转换到边剖非常简单. 我的做法是每个点的点权记录其到父亲节点的边的边权. 只要solve的时候不要把最上面的点记录在内就可以了. Tree Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a…
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions…
You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions can be one…
通过打懒标记实现区间取反,和线段树基本操作都差不多. 本题还是一道边权化为点权的问题. 200行巨长代码: 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int maxn=10010; 6 int head[maxn],cnt=0,total=0;//头结点 7 int fa[maxn],dep[maxn];//父亲,深度 8 int…
http://poj.org/problem?id=3237 (题目链接) 树链剖分模板题,然而这150+行的程序我调了一天,历经艰辛,终于ac.. 题意 给出一个n个节点的带权树,要求维护操作:1.求出树上两点之间的边权的最大值:2.更改一条边上的权值:3.将树上两点之间的所有边权取各自的相反数. solution 神奇的树链剖分+线段树维护查询和修改操作. 树链剖分时,我们将每条边的权值转换为除树根外每个节点上的权值(也就是对于每个节点与它父亲的边的权值转换到了自己的权值). 之后就是标准的…
[POJ3237]Tree Description You are given a tree with N nodes. The tree's nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. Th…
题意:在一棵N个节点,有边权的树上维护以下操作: 1:单边修改,将第X条边的边权修改成Y 2:区间取反,将点X与Y在树上路径中的所有边边权取反 3:区间询问最大值,询问X到Y树上路径中边权最大值 n<=10000 CAS<=20 思路:做了2天,改出来的一刻全身都萎掉了 边权转点权,点权就是它到父亲的边的边权,加一些反向标记 取反的标记TAG下传时不能直接赋值为-1,而是将原先的标记取反 多组数据时倍增数组,深度也需要清零 树链剖分不能取第一条边,需要+1 ; ..]of record min…
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 throughN − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions…