您当前的位置: 首页 > 

minato_yukina

暂无认证

  • 2浏览

    0关注

    138博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

P3128 [USACO15DEC]Max Flow P

minato_yukina 发布时间:2022-08-11 19:26:47 ,浏览量:2

在这里插入图片描述 链接 树上差分的点模板,只需记住两个点各自加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            
关注
打赏
1663570241
查看更多评论
0.1090s