链接 树上差分的点模板,只需记住两个点各自加1,公共祖先减一,公共祖先的父亲减一.还原是对子树求和,记住这些即可
#include
using namespace std;
const int maxn = 1e6+5;
const int INF = 1e9+7;
typedef long long ll;
typedef pair pii;
#define all(a) (a).begin(), (a).end()
#define pb(a) push_back(a)
vector G[maxn];
//前向星
// for(int i=head[u];i!=-1;i=nxt[i]) v = to[i]
//int nxt[maxn],head[maxn],to[maxn];// head[u],cnt 初始值是-1
//int tot = -1;
//void add(int u,int v){
// nxt[++tot] = head[u];
// head[u] = tot;
// to[tot] = v;
//}
int fa[maxn][31];int depth[maxn];
void dfs1(int u,int f){
fa[u][0]=f;depth[u] = depth[f] +1;
for(int i=1;i>n>>m;
for(int i=1;i>u>>v;
G[u].pb(v);G[v].pb(u);
}
dfs1(1,0);
while(m--){
int u,v;cin>>u>>v;
diff[u]++,diff[v]++;
int f1 = lca(u,v);
diff[f1]--;diff[fa[f1][0]]--;
}
int ans = 0;
dfs(1,0);
for(int i=1;i
关注
打赏