随笔分类 - 树论
摘要:[树链剖分]模板题 https://www.luogu.com.cn/problem/P3384 操作: 1 x y z (x,y)路径点权+z 2 x y 询问sum(x,y) 3 x z x的子树每个点+z 4 x 询问x的子树sum #define mid ((l+r)>>1) #define
阅读全文
摘要:[模板题]https://www.luogu.com.cn/problem/P3128 在(u,v)最短路径上每个点加上v,询问最后权值最大的点 const int N = 5e4 + 50,M = 1e5 +50; int h[N],e[M],ne[M],idx; void add(int a,i
阅读全文
摘要:[模板]https://www.luogu.com.cn/problem/P3379 const int N = 5e5 + 50,M = 1e6 +50; int h[N],e[M],ne[M],idx; void add(int a,int b) { e[idx]=b,ne[idx]=h[a],
阅读全文
摘要:https://www.luogu.com.cn/problem/P1807 int n,m; int h[N],e[N],ne[N],w[N],idx; void add(int a,int b,int c) { e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
阅读全文
摘要:1.时间戳 int dfn[N],vis[N],cnt; void dfs(int u) { vis[u]=1; dfn[u]=++cnt;//时间戳 for(int i=h[u]; ~i; i=ne[i]) { int j=e[i]; if(vis[j])continue; dfs(j); } }
阅读全文
摘要:https://www.luogu.com.cn/problem/P3000 最多删除k条边使得树的直径最小 二分答案,dfs的时候考虑结点u,now记录u的已经遍历的儿子的最大深度,len[j]表示j的最大深度,如果now + len[j] >= mid,把now那条边和j边 长的切断,更新now
阅读全文

浙公网安备 33010602011771号