题目html
简明题意:求最小割的必须割边和可行割边.ios
可行割边的断定法则:git
你可能有个直觉:流满的边必定是可行边.web
然而这是错的.如图:app
若是每条边的流量都为1.b流满了不表明它是必修边.svg
咱们对 缩点后,那么可行边的端点只能在不一样的强连通份量.spa
由于要知足最小割的话,割边必须是一些流的必经边,不然删除更小,与定义矛盾.code
而一个环的话是没有必经边可言的,因此只有端点在不一样的强连通份量的合法.xml
必须边必须是一个流的惟一瓶颈,不是惟一的那个的话则可替换.htm
由此能够看出当咱们增大一条必须割边的容量时,势必会使得最大流增大.
因此咱们的选择也必须知足这一性质,即 表示强连通份量的标号.
此时 是合法的流,知足条件.
Code:
#include<map> #include<set> #include<ctime> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<string> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #include<functional> #define lc (x<<1) #define rc (x<<1|1) #define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pi pair<int,int> #define fi first #define se second #define pb push_back #define IT iterator #define SZ(a) ((int)a.size()) #define all(a) a.begin(),a.end() using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int N=4010,M=12e4+10,size=1<<20,inf=-1u/2; //char buf[size],*p1=buf,*p2=buf; template<class o> void qr(o &x) { char c=gc; x=0; int f=1; while(!isdigit(c)){if(c=='-')f=-1; c=gc;} while(isdigit(c)) x=x*10+c-'0',c=gc; x*=f; } template<class o> void qw(o x) { if(x/10) qw(x/10); putchar(x%10+'0'); } template<class o> void pr1(o x) { if(x<0)x=-x,putchar('-'); qw(x); putchar(' '); } template<class o> void pr2(o x) { if(x<0)x=-x,putchar('-'); qw(x); puts(""); } int n,m,st,ed,d[N],c[N],q[N],l,r; struct edge{int y,next,c;}a[M]; int len=1,last[N],cur[N]; void ins(int x,int y,int c) {a[++len]=(edge){y,last[x],c}; last[x]=len;} void add(int x,int y,int c) {ins(x,y,c); ins(y,x,0);} void bfs() { q[l=r=1]=ed; ++c[d[ed]=1]; memcpy(cur+1,last+1,n<<2); for(int x=ed;l<=r;x=q[++l]) for(int k=last[x],y;k;k=a[k].next) if(!d[y=a[k].y]) {++c[d[y]=d[x]+1]; q[++r]=y;} } int dfs(int x,int f) { if(x==ed) return f; int s=0,t; for(int &k=cur[x],y,z;k;k=a[k].next) { y=a[k].y; z=a[k].c; if(z&&d[y]+1==d[x]) { s+=t=dfs(y,min(f-s,z)); a[k].c-=t; a[k^1].c+=t; if(s==f) return f; } } if(!--c[d[x]]) d[st]=n+1; ++c[++d[x]]; cur[x]=last[x]; return s; } int dfn[N],low[N],sta[N],top,num,id[N],cnt; bool v[N]; void tarjan(int x) { dfn[x]=low[x]=++num; v[sta[++top]=x]=1; for(int k=last[x],y,z;k;k=a[k].next) { y=a[k].y; z=a[k].c; if(z) { if(!dfn[y]) { tarjan(y); low[x]=min(low[x],low[y]); } else if(v[y]) low[x]=min(low[x],dfn[y]); } } if(dfn[x]==low[x]) { int z; cnt++; do { v[z=sta[top--]]=0; id[z]=cnt; } while(z^x); } } int main() { qr(n); qr(m); qr(st); qr(ed); for(int i=1,x,y,c;i<=m;i++) qr(x),qr(y),qr(c),add(x,y,c); bfs(); while(d[st]<=n) dfs(st,inf); for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i); for(int k=2;k<=len;k+=2) if(!a[k].c) pr1(id[a[k].y]!=id[a[k^1].y]),pr2(id[a[k^1].y]==id[st]&&id[a[k].y]==id[ed]); else puts("0 0"); return 0; }
=len;k+=2)
if(!a[k].c) pr1(id[a[k].y]!=id[a[k1].y]),pr2(id[a[k1].y]==id[st]&&id[a[k].y]==id[ed]); else puts(“0 0”); return 0; }