ABC239G,又是 AtCoder Library 的一天
你发现一个点可以拆成两个点,中间连一条代价为
大家可以手写网络流,也可以想我一样用 AtCoder Library 的 maxflow。
这里稍微讲一下它输出最小割残量网络的功能:有一个函数 mincut,返回类型为 vector<bool>,代表每个节点是否能通过网络流的
然后我只需要判断
这个 mincut 函数的功能或许可以启发我们残量网络的代码实现。
#include<bits/stdc++.h>
#include<atcoder/maxflow>
#define fo(i,a,b) for(I i(a),_ed(b);i<=_ed;++i)
using namespace std;using I=int;using LL=long long;using V=void;
I n,m;
#define ade add_edge
const LL Linf=1ll<<60;
vector<I>v;
I main(){ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
atcoder::mf_graph<LL>g(n+n+1);
fo(i,1,m){I u,v;cin>>u>>v;
g.ade(u+n,v,Linf);
g.ade(v+n,u,Linf);}
fo(i,1,n){I x;cin>>x;
g.ade(i,i+n,x);}
printf("%lld\n",g.flow(n+1,n));
vector<bool>ans=g.min_cut(n+1);
fo(i,1,n)if(ans[i]&&!ans[i+n])v.push_back(i);
printf("%d\n",v.size());
for(I i:v)printf("%d ",i);
return 0;}