题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28982#problem/I 给你一棵有边权的树,有两个操作:一个操作是输出l到r点之间的最大的边权,另一个操作是修改某条边的权值. 这题是树链剖分的简单模版题,代码如下: //修改单边权 #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; st…
SPOJ太慢了,SPOJ太慢了, 题意:给定n(n<=10000)个节点的树,每条边有边权,有两种操作:1.修改某条变的边权:2.查询u,v之间路径上的最大边权. 分析:树链剖分入门题,看这里:http://blog.sina.com.cn/s/blog_6974c8b20100zc61.html 轻重链剖分,线段树维护,复杂度 O(nlogn + q* logn * logn ) SPOJ太慢了,我知道我写的应该是没错了, 最后把自己宏定义的max和min去掉之后终于过了,傻逼笑呵呵了..为啥…
题意:一棵包含N 个结点的树,每条边都有一个权值,要求模拟两种操作:(1)改变某条边的权值,(2)询问U,V 之间的路径中权值最大的边. 思路:最近比赛总是看到有树链剖分的题目,就看了论文,做了这题,思路论文上讲的很清楚了,好长时间没写线段树了,错了好几遍.对树进行轻重边路径剖分.对于询问操作,我们可以分别处理两个点到其最近公共祖先的路径.路径可以分解成最多O(log N)条轻边和O(log N)条重路径,那么只需考虑如何维护这两种对象.对于轻边,我们直接处理即可.而对于重路径,我们只需用线段树…
人生第一道树链剖分的题目,其实树链剖分并不是特别难. 思想就是把树剖成一些轻链和重链,轻链比较少可以直接修改,重链比较长,用线段树去维护. 貌似大家都是从这篇博客上学的. #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; + ; int n; int tot; vector<int> G[maxn]; i…
QTREE - Query on a tree #tree You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3...N-1. We will ask you to perfrom some instructions of the following form: CHANGE i ti : change the cost of the i-th e…
题意: 知道了一颗有  n 个节点的树和树上每条边的权值,对应两种操作: 0 x        输出 当前节点到 x节点的最短距离,并移动到 x 节点位置 1 x val   把第 x 条边的权值改为 val 题意: 知道了一颗有  n 个节点的树和树上每条边的权值,对应两种操作: 0 x        输出 当前节点到 x节点的最短距离,并移动到 x 节点位置 1 x val   把第 x 条边的权值改为 val LCA +RMQ+树状数组 #include <cstdio> #includ…
/* 只是一道树链刨分的入门题,作为模板用. */ #include<stdio.h> #include<string.h> #include<iostream> #include<map> #include<string.h> #include<stdlib.h> #include<math.h> using namespace std; #define N 11000 #define inf 0x3fffffff in…
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2082 树链剖分模版题,求和,修改单边权. #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; ; struct EDGE { int to , next; LL cost; }edg…
题目链接:http://poj.org/problem?id=2763 n个节点的树上知道了每条边权,然后有两种操作:0操作是输出 当前节点到 x节点的最短距离,并移动到 x 节点位置:1操作是第i条边的边权变成x. 树链边权剖分的模版题,修改单边权和求和. //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <cstdio> #include…
树链剖分的第一题,易懂,注意这里是边. #include<queue> #include<stack> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define INF 99999999 #define ll __int64 #define lson l,m,rt<<1 #d…