http://uoj.ac/problem/217
题意就不X了,思路在这:
居然一开始把sap里面的mn设置为inf了,我是傻逼。。
#include#include #include #include #include #define inf 0x3f3f3f3fint go[200005],first[200005],next[200005],flow[200005],op[200005],dis[200005],cnt[200005];int tot,S,T,t,s,sz,son[200005],du[200005],n,nodes;bool flag;int read(){ int t=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){ if (ch=='-') f=-1;ch=getchar();} while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();} return t*f;}void insert(int x,int y,int z){ tot++; go[tot]=y; next[tot]=first[x]; first[x]=tot; flow[tot]=z;}void add(int x,int y,int z){ insert(x,y,z);op[tot]=tot+1; insert(y,x,0);op[tot]=tot-1;}void add(int x,int y,int low,int high){ int F=high-low; add(x,y,F);du[x]-=low;du[y]+=low;}int build(int l,int r,int op){ int k=++sz; add(s,k,0,inf);add(k+2*n-1,t,0,inf); add(4*n-2+l,k,0,inf);if (op&&r =nodes) return sum; } if (flow[i]) mn=std::min(mn,dis[pur]); } if (sum==0){ cnt[dis[x]]--; if (cnt[dis[x]]==0){ dis[S]=nodes; }else{ dis[x]=mn+1; cnt[dis[x]]++; } } return sum;}int mxflow(){ int res=0,tim=0; while (dis[S] 0) add(S,i,du[i]); else if (du[i]<0) add(i,T,-du[i]); int ans1=mxflow(); memset(dis,0,sizeof dis); memset(cnt,0,sizeof cnt); add(t,s,inf); int ans=mxflow(); printf("%d\n",ans);}