用树链剖分求LCA的模板: 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 const int maxn=40005; 5 int n,m; 6 int head[maxn],to[maxn<<1],w[maxn<<1],nxt[maxn<<1],tot; 7 int fa[maxn],dep[maxn],son[maxn],top[maxn],size[ma…
Description A rooted tree is a well-known data structure in computer science and engineering. An example is shown below: In the figure, each node is labeled with an integer from {1, 2,...,16}. Node 8 is the root of the tree. Node x is an ancestor of…
Code: #include<cstdio> #include<cstring> #include<vector> #include<algorithm> using namespace std; const int maxn=40000+3; typedef long long ll; ll dis[maxn]; int son[maxn],siz[maxn],rank1[maxn],p[maxn],top[maxn]; struct Edge { int…
Luogu 2590 [ZJOI2008]树的统计 / HYSBZ 1036 [ZJOI2008]树的统计Count (树链剖分,LCA,线段树) Description 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u v: 询问从点u到点v的路径上的节点的最大权值 III. QSUM u v: 询问从点u到点v的路径上的节点的权值和 注意:从点u到点v的路…