Bzoj 1797: [Ahoi2009]mincut min cut

Source: Internet
Author: User

1797: [Ahoi2009]mincut min cut time limit:10 Sec Memory limit:162 MB
submit:2076 solved:885
[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 M 1 10 50 6 1000 20000 2 20 200 7 1000 40000 3 200 2000 8 2000 50000 4 200 2000 9 30 00 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

Analysis:

We find that the minimum cut is to cut all the paths from S to T, that is, if we remove one edge of the smallest cut (u,v), we can no longer find a way to replace it, because the change in the minimum cut must be full flow, so if two points in a strong connected component, We can find another path from u to v ... So as long as the tarjan contraction point, the two points of the full flow edge is not the same strong connected component can be the smallest cut feasible edge ...

Because if the residual network can be from S to u, then there must be a reverse edge from u to S, so s and u must be in the same strongly connected component ... So it is also possible to determine whether the SUVT in the same strong connected component to find the necessary side ...

Code:
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdio>5#include <queue>6 //by Neighthorn7 #defineINF 0x3f3f3f3f8 #defineM 60000*39 using namespacestd;Ten //Dapeng Day with the wind, soaring 90,000 miles One  A Const intmaxn=4000+5, maxm=60000*2+5; -  - intn,m,s,t,cnt,id[maxm],hd[maxn],to[maxm],fl[maxm],nxt[maxm],vis[maxn],pos[maxn],flag[maxm],ans1[maxm],ans2[ MAXM]; the  - intC,TIM,TAIL,MP[MAXN],DFN[MAXN],LOW[MAXN],STK[MAXN],INSTK[MAXN]; -  -InlinevoidAddintSintXintYintl) { +fl[cnt]=s;id[cnt]=l;to[cnt]=y;nxt[cnt]=hd[x];flag[cnt]=1; hd[x]=cnt++; -fl[cnt]=0; id[cnt]=m;to[cnt]=x;nxt[cnt]=hd[y];flag[cnt]=0; hd[y]=cnt++; + } A  atInlineBOOLBFsvoid){ -memset (pos,-1,sizeof(POS)); -     intHead=0, tail=0, Q[MAXN]; -q[0]=s,pos[s]=0; -      while(head<=tail) { -         inttop=q[head++]; in          for(inti=hd[top];i!=-1; i=Nxt[i]) -             if(pos[to[i]]==-1&&Fl[i]) topos[to[i]]=pos[top]+1, q[++tail]=To[i]; +     } -     returnpos[t]!=-1; the } *  $InlineintFindintVintf) {Panax Notoginseng     if(v==T) -         returnF; the     intres=0, T; +      for(inti=hd[v];i!=-1&&f>res;i=Nxt[i]) A         if(pos[to[i]]==pos[v]+1&&Fl[i]) theT=find (To[i],min (f-res,fl[i)), fl[i]-=t,fl[i^1]+=t,res+=T; +     if(!Res) -pos[v]=-1; $     returnRes; $ } -  -InlinevoidDinic (void){ the      while(BFS ()) -          while(Find (S,inf));Wuyi } the  -InlinevoidTarjan (introot) { Wudfn[root]=low[root]=++tim;stk[++tail]=root;instk[root]=1; -      for(inti=hd[root];i!=-1; i=Nxt[i]) About         if(Fl[i]) { $             if(dfn[to[i]]==0) -Tarjan (To[i]), low[root]=min (Low[root],low[to[i]]); -             Else if(Instk[to[i]]) -low[root]=min (Low[root],dfn[to[i]]); A         } +     if(low[root]==Dfn[root]) { the         inttmp C++; -          Do{ $tmp=stk[tail--];instk[tmp]=0; mp[tmp]=C; the} while(tmp!=root); the     } the } the  -Signed Main (void){ inmemset (hd,-1,sizeof(HD)); thememset (Vis,0,sizeof(Vis)); thememset (Low,0,sizeof(Low)); Aboutmemset (DFN,0,sizeof(DFN)); thememset (INSTK,0,sizeof(INSTK)); thescanf"%d%d%d%d",&n,&m,&s,&T); the      for(intI=1, s,x,y;i<=m;i++) +scanf"%d%d%d",&x,&y,&s), add (s,x,y,i); -Dinic (); C=tim=tail=0; the      for(intI=1; i<=n;i++)Bayi         if(!Dfn[i]) the Tarjan (i); the      for(intI=1; i<=n;i++) -          for(intj=hd[i];j!=-1; j=Nxt[j]) -             if(flag[j]&&fl[j]==0) theAns1[j]= (Mp[i]==mp[to[j])?0:1), ans2[j]= (Mp[i]==mp[s]&&mp[to[j]]==mp[t])?1:0); the      for(intI=0; i<cnt;i+=2) theprintf"%d%d\n", Ans1[i],ans2[i]); the     return 0; -}//The cap ou pas Cap. Cap.
View Code

by Neighthorn

Bzoj 1797: [Ahoi2009]mincut 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.