[BZOJ3698] Xww problem (with Yuanhui upper and lower boundary maximum flow + explanation) __ Network flow

Source: Internet
Author: User
topic:

I am the hyperlink :

If you build a picture, it's the same as a Yuanhui feasible flow

Solution Method:
Runs the maximum stream of SS to TT on the new graph (additional Yuanhui)
If the new graph is full flow, there must be a feasible flow
Remember at this time ∑f (s,i) =sum1∑f (s,i) =sum1
Remove the edge of the T->s and run the maximum flow of s to T on the new graph (original Yuanhui)
Remember at this time ∑f (s,i) =sum2∑f (s,i) =sum2
The final answer is SUM1+SUM2 sum1+sum2

The proof is probably this:
Add the role of additional Yuanhui: in order to meet the flow balance conditions, in the new diagram of the corresponding recharge or shunt
any feasible flow of s->t in a new graph is a feasible flow of the original image as long as the edge of the attached Yuanhui is filled with a full stream .
After running the maximum flow of the SS->TT, the equivalent is to make the connection to attach the Yuanhui edge full flow, and then to find a feasible flow
Then remove the edge of the T->s (make the s->t into a Yuanhui network flow diagram), the maximum flow that runs s to T, plus the maximum flow that runs out, is a feasible maximum flow in the original image (not to reconnect the edge, but to remove the edge of the t->s, that is, to broaden it again.) )

So for this topic, with the inspiration of the previous question, we know this "matrix, and, limit, maximum" can be transformed into network flow problem, source point line, Edge is restricted and; column connection point, Edge for limited and; rows and columns are connected to limit to the corresponding points; they are connected to the additional Yuanhui, to replenish the flow ; Even the INF side of the T->s (maximum stream should be asked once after removed)

The mapping method of this problem is:
For each row i,s->i,[a (I,n), A (i,n) +1]
For each column j,j->t,[a (N,J), A (n,j) +1]
For each point (I,J), I->j,[a (I,j), A (i,j) +1]
And then in accordance with the Yuanhui has the upper and lower bounds of the map can be modified code:

#include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream
> #define INF 1e9 using namespace std;
const int n=100005; int Tot=-1,nxt[n],point[n],v[n],cur[n],remind[n],dis[n],r[105][105],l[105][105],pip[105][105],d[n];d ouble ll[105
] [105];
    void AddLine (int x,int y,int cap) {++tot; nxt[tot]=point[x]; point[x]=tot; v[tot]=y; remind[tot]=cap; ++tot; Nxt[tot]=point[y]; Point[y]=tot; V[tot]=x;
remind[tot]=0;
    int dfs (int now,int t,int limit) {if (now==t | |!limit) return limit;
    int flow=0,f;
        for (int i=cur[now];i!=-1;i=nxt[i]) {cur[now]=i;
            if (dis[v[i]]==dis[now]+1 && (F=dfs (V[i],t,min (limit,remind[i)))) {limit-=f;
            Flow+=f;
            Remind[i]-=f;
            Remind[i^1]+=f;
        if (!limit) break;
} return flow;
    BOOL BFs (int s,int t) {queue<int>q;
    Q.push (s);
    memset (dis,0x7f,sizeof (dis)); Dis[s]=0;
    for (int i=1;i<=t;i++) cur[i]=point[i];
        while (!q.empty ()) {int X=q.front (); Q.pop (); for (int i=point[x];i!=-1;i=nxt[i]) if (Dis[v[i]]>inf && remind[i]) {Q.push (v[i)); Dis[v[i]
    ]=dis[x]+1;}
Return dis[t]<inf;
    int main () {memset (point,-1,sizeof (point)); Memset (nxt,-1,sizeof (NXT));
    int n,s,t,ss,tt;
    scanf ("%d", &n); s=n*2+1; t=s+1; ss=t+1;
    tt=ss+1; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf ("%lf", &ll[i][j)), R[i][j]=ceil (Ll[i][j)), l[i][

    J]=floor (Ll[i][j]);
        for (int i=1;i<n;i++) {d[s]-=l[i][n],d[i]+=l[i][n],addline (s,i,r[i][n]-l[i][n]);
    D[i+n]-=l[n][i],d[t]+=l[n][i],addline (I+n,t,r[n][i]-l[n][i]); for (int i=1;i<n;i++) for (int j=1;j<n;j++) D[i]-=l[i][j],d[j+n]+=l[i][j],addline (i,j+n,r[i][j]-
    L[I][J]), Pip[i][j]=tot;
    int in=0,out=0; for (int i=1;i<=t;i++) {if (d[i]>0) AddlinE (Ss,i,d[i]), in+=d[i];
    if (d[i]<0) AddLine (I,tt,-d[i]), out-=d[i];
    } addline (t,s,inf); int lj=tot;
    if (in!=out) {printf ("No"); return 0;}

    int maxflow=0,ans=0;

    while (BFS (SS,TT)) Maxflow+=dfs (Ss,tt,inf);

    if (maxflow!=in) {printf ("No"); return 0;}

    remind[lj]=remind[lj^1]=0;

    while (BFS (s,t)) Maxflow+=dfs (S,t,inf);

    for (int i=1;i<n;i++) for (int j=1;j<n;j++) ANS+=REMIND[PIP[I][J]]+L[I][J];
printf ("%d", ans*3); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.