题意 题目链接 Sol 树上差分模板题 发现自己傻傻的分不清边差分和点差分 边差分就是对边进行操作,我们在\(u, v\)除加上\(val\),同时在\(lca\)处减去\(2 * val\) 点差分是对点操作,我们在\(u, v\)处加上\(val\),在\(lca\)和\(fa[lca]\)处减去\(val\) 就本题而言,属于点差分 #include<bits/stdc++.h> const int MAXN = 1e5 + 10; using namespace std; inline…
题目描述 Farmer John has installed a new system of N-1N−1 pipes to transport milk between the NN stalls in his barn (2 \leq N \leq 50,0002≤N≤50,000), conveniently numbered 1 \ldots N1-N. Each pipe connects a pair of stalls, and all stalls are connected t…
题目:https://www.luogu.org/problemnew/show/P3128 倍增求 lca 也写错了活该第一次惨WA. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; ],dep[maxn],s[maxn],mx; bool vis[maxn]; struct N{ int to,nx…
题目:https://www.luogu.org/problemnew/show/P3128 树上差分.用离线lca,邻接表存好方便. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ,M=1e5+; ],nxt[M<<],ans; bool vis[N]; struct Ed{ ,):nxt(n),to(…
因为徐州现场赛的G是树上差分+组合数学,但是比赛的时候没有写出来(自闭),背锅. 会差分数组但是不会树上差分,然后就学了一下. 看了一些东西之后,对树上差分写一点个人的理解: 首先要知道在树上,两点之间只有一条路径.树上差分就是在树上用差分数组,因为是在树上的操作,所以要用到lca,因为对于两点a,b,从a到b这一条链就是a-->lca(a,b)-->b,这是一条链. 其次,树上差分的两种操作:一种是对点权的,另一种是对边权的. 对于点权: 在树上将路径的起点a+1和终点b+1,lca(a,b…
P3128 [USACO15DEC]最大流Max Flow 题目描述 Farmer John has installed a new system of  pipes to transport milk between the  stalls in his barn (), conveniently numbered . Each pipe connects a pair of stalls, and all stalls are connected to each-other via path…
P3128 [USACO15DEC]最大流Max Flow 题目描述 Farmer John has installed a new system of N-1N−1 pipes to transport milk between the NN stalls in his barn (2 \leq N \leq 50,0002≤N≤50,000), conveniently numbered 1 \ldots N1…N. Each pipe connects a pair of stalls,…
###题目链接### 题目大意: 给你一棵树,k 次操作,每次操作中有 a  b 两点,这两点路上的所有点都被标记一次.问你 k 次操作之后,整棵树上的点中被标记的最大次数是多少. 分析: 1.由于数据太大,故可以采用树上差分中的点差分来做到 O(1)标记. 2.需要用 tarjan 离线找出两点间的 lca . 3.在树上点差分中,还需要找到 lca 的父亲节点.由于在 tarjan 求 lca 时,并查集中的 pre[lca] 并非一直指向的是 lca 的父亲节点,故需要再开一个 fa[]…
题目描述 Farmer John has installed a new system of  pipes to transport milk between the  stalls in his barn (), conveniently numbered . Each pipe connects a pair of stalls, and all stalls are connected to each-other via paths of pipes. FJ is pumping milk…
题目描述 Farmer John has installed a new system of  pipes to transport milk between the  stalls in his barn (), conveniently numbered . Each pipe connects a pair of stalls, and all stalls are connected to each-other via paths of pipes. FJ is pumping milk…