intmain(){scanf("%d %d",&N,&M);int xx = N+1;int yy = N+2;
N +=2;rep(i,1,M){int x,y,l,r;scanf("%d %d %d %d",&x,&y,&l,&r);
a[i]=Node(x,y,G[x].size(),r);add_edge(x,y,r-l);add_edge(x,xx,l);add_edge(yy,y,l);}int res =0;rep(i,0,G[yy].size()){
res += G[yy][i].cap;}if(max_flow(yy,xx)== res){puts("YES");rep(i,1,M){printf("%d\n",a[i].ca - G[a[i].u][a[i].si].cap);}}elseputs("NO");}
有汇源有上下界最大流
intmain(){int s,t;scanf("%d %d %d %d",&N,&M,&s,&t);int xx = N+1;int yy = N+2;
N +=2;rep(i,1,M){int x,y,l,r;scanf("%d %d %d %d",&x,&y,&l,&r);add_edge(x,y,r-l);add_edge(x,xx,l);add_edge(yy,y,l);}add_edge(t,s,INF);int res =0;rep(i,0,G[yy].size()){
res += G[yy][i].cap;}if(max_flow(yy,xx)== res){
edge &e = G[t][G[t].size()-1];
edge &e2 = G[s][G[s].size()-1];
res = e2.cap;
e2.cap = e.cap =0;
res +=max_flow(s,t);printf("%d\n",res);}elseputs("please go home to sleep");}
有汇源有上下界最小流
intmain(){int s,t;scanf("%d %d %d %d",&N,&M,&s,&t);int xx = N+1;int yy = N+2;
N +=2;rep(i,1,M){int x,y,l,r;scanf("%d %d %d %d",&x,&y,&l,&r);add_edge(x,y,r-l);add_edge(x,xx,l);add_edge(yy,y,l);}int res =0;rep(i,0,G[yy].size()-1){
res += G[yy][i].cap;}int ans =max_flow(yy,xx);add_edge(t,s,INF);
ans +=max_flow(yy,xx);if(ans == res){printf("%d\n",G[s][G[s].size()-1].cap);}elseputs("please go home to sleep");}
无汇源有上下界可行流int main(){ scanf("%d %d",&N,&M); int xx = N+1; int yy = N+2; N += 2; rep(i,1,M) { int x,y,l,r; scanf("%d %d %d %d",&x,&a