sprads @ 2022-01-05 22:37:02
为什么这样
ll dinic(int x,ll In){
if(x == t)return In;
ll Bk = 0,res;
for(int i = st[x];i && In;i = Next[i]){
int y = ver[i];
if(edge[i] && d[y] == d[x] + 1){
res = dinic(y,min(In,edge[i]));
In -= res,Bk += res;
edge[i] -= res,edge[i ^ 1] += res;
}
st[x] = Next[i];//here
}
if(Bk == 0)
d[x] = 0;
return Bk;
}
如此之慢 提交记录
而这样
ll dinic(int x,ll In){
if(x == t)return In;
ll Bk = 0,res;
for(int i = st[x];i && In;i = Next[i]){
int y = ver[i];
if(edge[i] && d[y] == d[x] + 1){
res = dinic(y,min(In,edge[i]));
In -= res,Bk += res;
edge[i] -= res,edge[i ^ 1] += res;
}
if(!edge[i])st[x] = Next[i];//here
}
if(Bk == 0)
d[x] = 0;
return Bk;
}
却快了不少提交记录
by Celtic @ 2022-01-05 22:50:33
因为上面的那个会多跑一条边
by Celtic @ 2022-01-05 22:51:01
你考虑如果你剩下的流量不够跑完
by Celtic @ 2022-01-05 22:51:16
那你下次还是得从
by Celtic @ 2022-01-05 22:51:56
但是上面这样写
by Celtic @ 2022-01-05 22:52:23
上面那个复杂度不对应该
by sprads @ 2022-01-05 22:57:01
@Imitatоrs 谢谢帮助,弄懂了