"BZOJ-1797" Mincut min cut max flow + Tarjan + pinch point

Source: Internet
Author: User

1797: [Ahoi2009]mincut min cut time limit:10 Sec Memory limit:162 MB
submit:1685 solved:724
[Submit] [Status] [Discuss] Description

A. Two countries are at war, of which there are N transit stations in the material transport network of country A, the one-way road of M. With the 1≤i≤m road connected to the Vi,ui two transit stations, the Terminal VI can reach the UI transit through the road, if cut off the road, it will cost CI. Now the B country wants to find a path cut-off scheme, so that the transfer station s can not reach the broker T, and cut off the cost of the minimum path. Small cocoa at a glance, this is a problem of minimum cut. But the little cocoa that loves to think is not limited to this. Now he raises two questions for each one-way road: Question one: Is there a minimum cost path cut-off scheme in which the road is cut off? Question two: Is the path cut off for any one of the least-cost route-cutting schemes? Now please answer these two questions.

Input

The first line has 4 positive integers, followed by n,m,s and T. Line 2nd to (m+1) row of 3 positive integers per line v,u,c means that the V-Broker to u transit between a one-way road connection, the starting point of the one-way road is V, the end point is U, cut it at the cost of C (1≤c≤100000). Note: There may be several roads connected directly between the two transit stations. There may be one or more spaces between adjacent two numbers on the same line.

Output

For each one-way edge, in the order of input, output a row, containing two non-0, or 1 integers, respectively, the answer to question one and question two (where Output 1 indicates yes, output 0 indicates no). The same line is separated by a space and there is no extra space at the beginning and end of each line.

Sample Input6 7 1 6
1 2 3
1 3 2
2 4 4
2 5 1
3 5 5
4 6 2
5 6 3
Sample Output1 0
1 0
0 0
1 0
0 0
1 0
1 0
HINT

The i+1 line input edge is the I-number edge, then {1,2},{6,7},{2,4,6} is the only three minimum cost cut scheme. They are {1,2,4,6,7}, and the intersection is. Data size and conventions test data size as shown in the table below data number n M data number n M1 10 50 6 1000 20000 2 20 200 7 1000 40000 3 200 2000 8 2000 50000 4 200 2000 9 300 0 60000 5 1000 20000 10 4000 60000

In 2015.4.16, a new group of data may be stuck in a previously available program.

Source

Day1

Solution

First, the minimum cut-max flow theorem, it is obvious to think of the maximum flow

So the question is, is the judgment on the choice of sides?

Consider processing on the residual network of the minimum cut (maximum flow), then think of the tarjan+ shrinkage point

After discussion, the following judgments can be found:

For question 1:

If the left and right endpoints of an edge are not in the same SCC, then 1, otherwise 0

For question 2:

Satisfies the left and right end of an edge must have an endpoint with an SCC, another endpoint with the T with the SCC, at this time 1, otherwise 0

Of course there is a special case, that is, this side has never been cut, then it is obvious that the problem 1 and 2 are 0

Code
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();}  while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}//Quick Read#defineMAXN 4000+100#defineMAXM (60000+100) * *structdata{int  from, To,next,cap;} EDGE[MAXM];intHead[maxn],cnt=1, CUR[MAXN];voidAddintUintVintW) {CNT++;EDGE[CNT].TO=V;EDGE[CNT]. from=U;edge[cnt].next=head[u];head[u]=cnt;edge[cnt].cap=W;}voidInsertintUintVintW) {Add (u,v,w); Add (V,u,0);}//Add EdgeintN,m,s,t;intDIS[MAXN],Q[MAXN];BOOLBFs () { for(intI=1; i<=n; i++) dis[i]=-1; intHe=0, Ta=1; q[0]=s; dis[s]=0;  while(he<ta) {            intnow=q[he++];  for(intI=head[now]; I I=edge[i].next)if(dis[edge[i].to]==-1&&edge[i].cap) dis[edge[i].to]=dis[now]+1, q[ta++]=edge[i].to; }    returndis[t]!=-1;}intDfsintLocintLow ) {    if(loc==t)returnLow ; intW,used=0;  for(intI=cur[loc]; I I=edge[i].next)if(dis[edge[i].to]==dis[loc]+1) {W=dfs (Edge[i].to,min (low-used,edge[i].cap)); Edge[i].cap-=w;edge[i^1].cap+=W; if(EDGE[I].CAP) cur[loc]=i; Used+=w;if(Used==low)returnLow ; }    if(!used) dis[loc]=-1; returnused;}#defineINF 0x7fffffffintDinic () {inttmp=0;  while(BFS ()) { for(intI=1; i<=n; i++) cur[i]=Head[i]; TMP+=DFS (S,inf); }    returntmp;}//Maxflow dinicintStack[maxn],st,qcnt,tot;intDFN[MAXN],LOWW[MAXN],BELONG[MAXN],NUM[MAXN];BOOLVISIT[MAXN];voidTarjan (intx) {Dfn[x]=loww[x]=++tot; Stack[++st]=x; visit[x]=1;  for(intI=HEAD[X]; I I=edge[i].next)if(EDGE[I].CAP)//According to test instructions, in Tarjan time need to make this judgment, otherwise there will be a problem {if(!Dfn[edge[i].to])                        {Tarjan (edge[i].to); if(Loww[edge[i].to]<loww[x]) loww[x]=Loww[edge[i].to]; }                Else if(Visit[edge[i].to] && dfn[edge[i].to]<loww[x]) loww[x]=Dfn[edge[i].to]; }    if(dfn[x]==Loww[x]) {qcnt++;intu;  while(x!=u) u=stack[st--],num[qcnt]++, Visit[u]=0, belong[u]=qcnt; }}//Tarjan SCCintMain () {n=read (), M=read (), S=read (), t=read ();  for(intU,v,c,i=1; i<=m; i++) U=read (), V=read (), c=read (), insert (U,V,C); intmaxflow=Dinic ();  for(intI=1; i<=n; i++)        if(!Dfn[i])    Tarjan (i);  for(intAns1,ans2,u,v,i=2; i<=cnt; i+=2) {u=edge[i]. from, v=edge[i].to; if(EDGE[I].CAP) ans1=0, ans2=0; Else                     {                        if(belong[u]!=Belong[v]) ans1=1;Elseans1=0; if(Belong[u]==belong[s] && belong[v]==belong[t]) ans2=1;ElseAns2=0; } printf ("%d%d\n", ANS1,ANS2); }    return 0;}

Should have done fast, however ... I have two variables of the wrong brain. Pit for a long time .... SB mistake ruin a life!!

"BZOJ-1797" Mincut min cut max flow + Tarjan + pinch point

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.