Poj 2125 "min cut"

Source: Internet
Author: User

Topic: A direction-free graph, the cost of deleting a point of all the < Span class= "Mrow" id= "mathjax-span-2" > a i Span style= "Display:inline-block; width:0px; Height:2.279em; " > , the cost of removing all the edges of a point is < Span class= "Mrow" id= "mathjax-span-7" > b i Span style= "Display:inline-block; width:0px; Height:2.279em; " > To remove the minimum cost of all edges

Split a point I into two points i,i '
Build diagram:
S-I, Flow < Span class= "Mrow" id= "mathjax-span-12" > b i Span style= "Display:inline-block; width:0px; Height:2.279em; " >
I-j ', Flow inf
I ' T, flow a i
Then run the minimum cut Qaq

If it is a table, you can also split it into columns like this ...

If the requirement is the minimum number of times, you can precede the weights with a large number ...

#include <iostream>#include <algorithm>#include <cstring>#include <string>#include <ctime>#include <cmath>#include <cstdlib>#include <cstdio>#define N 2005#define M 50005#define INF 1000000000using namespace STD;intn,m,siz=1, s,t;intFIRST[N],NEXT[M],TO[M],LEN[M];intD[n],p[n],c[n],r[n],v[n];voidInser (intXintYintW) {next[++siz]=first[x];    First[x]=siz;    To[siz]=y; Len[siz]=w;}voidAdd_edge (intXintYintW) {Inser (x,y,w), Inser (Y,x,0);}BOOLBFS () {intHead=0, tail=1;memset(d,0,sizeof(d)); d[p[1]=s]=1; while(Head^tail) {intX=p[++head]; for(intI=first[x];i;i=next[i])if(!d[to[i]]&&len[i]) d[p[++tail]=to[i]]=d[x]+1; }returnD[T];}intDfsintXintFlow) {if(x==t)returnFlowintret=0; for(intI=first[x];i&&flow;i=next[i])if(d[to[i]]==d[x]+1&&len[i]) {intW=dfs (To[i],min (flow,len[i));            Len[i]-=w; len[i^1]+=w;            Ret+=w;        Flow-=w; }if(!ret) d[x]=0;returnRET;}intDinic () {intret=0; while(BFS ())) Ret+=dfs (S,inf);returnRET;}voidDFS (intx) {v[x]=true; for(intI=first[x];i;i=next[i])if(!v[to[i]]&&len[i]) DFS (To[i]);}intMain () {scanf("%d%d", &n,&m); s=n<<1|1, t=s+1; for(intX,i=1; i<=n;i++)scanf("%d", &x), Add_edge (i+n,t,x); for(intX,i=1; i<=n;i++)scanf("%d", &x), Add_edge (s,i,x); for(intX,y,i=1; i<=m;i++) {scanf("%d%d", &x,&y);    Add_edge (X,y+n,inf); }printf("%d\n", Dinic ());inttot=0; DFS (S); for(intI=1; i<=n;i++) {if(!v[i]) r[i]=1, tot++;if(V[i+n]) c[i]=1, tot++; }printf("%d\n", tot); for(intI=1; i<=n;i++) {if(R[i])printf("%d-\n", i);if(C[i])printf("%d +\n", i); }return 0;}

Poj 2125 "min cut"

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.