2017 Qingdao online race smallest Minimum cut max flow minimum cut problem (deepen understanding of maximum flow problem)

Source: Internet
Author: User



Theorem 1: Maximum flow minimum cut quantification: In any network, the value of the maximum stream equals the minimum cut capacity

Theorem 2: In any network, if F is a stream, cut (s,t) is a cut, and the value of F equals the capacity of cut cut (s,t), then f is a maximum flow

Conclusion 1: The maximum flow, the minimum cut Cut (s,t), the positive cutting edge of the flow = capacity, reverse cutting edge flow of 0. Otherwise it can be augmented.

Corollary 1: If F is a stream in the network, Cut (s,t) is a cut, then the value of F does not exceed the capacity of cut cut (s,t).

Corollary 2: The maximum stream in the network does not exceed the capacity of any cut

When the maximum flow is finding the augmented path, when it is not found, then the maximum flow is at this time;

The meaning of the theorem, the minimum cut capacity = maximum flow, which we understand;

(1) When running the maximum flow, the minimum cut must be full flow, that is, the minimum cut per side flow is equal to the capacity

(2) When running the maximum flow, the capacity of each edge minus the flow is the residual network at this time

(3) After running the maximum flow, and then through the reduce,clearflow operation, at this time to find the maximum flow, the result is 0

The minimum number of cuts on the maximum flow basis of this question makes S and T become independent points,

From the analysis of results,

In the drawing of the time weight * A large number +1 and then run out of the maximum flow% This large number is the result;

I asked a lot of people and got the answer.

  Edge Weight  *  A large number is 0, you + 1, if this is full edge flow,% that large number is 1, set minimum cut of the minimum number of sides is x, then flow% that large number ==x



#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include < math.h> #include <cstring> #include <string> #include <queue> #include <stack> #include < stdlib.h> #include <list> #include <map> #include <set> #include <bitset> #include <vector > #define MEM (A, B) memset (A,b,sizeof (a)) #define FINDX (x) lower_bound (b+1,b+1+bn,x)-B #define FIN freopen ("input.t XT "," R ", stdin) #define FOUT freopen (" Output.txt "," w ", stdout) #define S1 (n) scanf ("%d ", &n) #define SL1 (n) scan F ("%i64d", &n) #define S2 (n,m) scanf ("%d%d", &n,&m) #define SL2 (n,m) scanf ("%i64d%i64d", &n,&m) #
Define PR (N) printf ("%d\n", N) using namespace std;
typedef long Long LL;
Const Double Pi=acos (-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e4+5;
const int mod=1e9+7;
const int mod=1e9+7;


int dir[5][2]={0,1,0,-1,1,0,-1,0}; struct node{int v,w,next;//U v from u-v weight to W}EDGE[MAXN];
int head[maxn],num[maxn],start,end,cnt,sum;
    void Init () {cnt=0;
MEM (head,-1);
    } void Add (int u,int v,int W) {/* Creates a map or an according to the test instructions, there is a direction to the diagram of the inverse of the 0 map-like */edge[cnt].v=v;
    Edge[cnt].w=w;
    Edge[cnt].next=head[u];
    head[u]=cnt++;
    Edge[cnt].v=u;
    edge[cnt].w=0;
    EDGE[CNT].NEXT=HEAD[V];
head[v]=cnt++;
    } int BFs () {queue<int>q;
    MEM (num,0);
    Num[start]=1;
    Q.push (start); while (!
        Q.empty ()) {int T=q.front ();
        Q.pop ();
        if (t==end) return 1; for (int i=head[t];i!=-1;i=edge[i].next)//chain forward star Access find augmented path {int t1= edge[i].v;//next node int t2= edge[i].w;//Current point weights if (t2&&num[t1]==0)//current point exists and the next point does not have access {Num[t1]=num[t]
                +1;//Point =1 if (t1==end)//end return 1;
            Q.push (t1);
}}} return 0; } int dfs (int u,int maxflow) {if (u==end)
        return maxflow;

    int res=0; for (int i=head[u];i!=-1;i=edge[i].next) {int t1=edge[i].v;//next node int t2=edge[i].w;//current node I F (t2&&num[t1]==num[u]+1) {int Temp=dfs (t1,min (MAXFLOW-RES,T2));//Select a part of the edge with a small stream
            [i].w-=temp;//to reduce edge[i^1].w+=temp;//reverse increase res+=temp;
        if (Res==maxflow) return res;
    }} if (!res) num[u]=-1;
return res;
    } void Dinic () {int ans=0;
    while (BFS ()) {Ans+=dfs (start,inf);

} printf ("%d\n", ans%10005);
    } int main () {int t;
    cin>>t;
      while (t--) {init ();
      int n,m;
      int x, y, Z;
      scanf ("%d%d", &n,&m);
      scanf ("%d%d", &start,&end);
        for (int i=1;i<=m;i++) {scanf ("%d%d%d", &x,&y,&z);
      Add (x,y,z*10005+1);
    } dinic ();
} return 0;
 }


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.