Maximum Flow +tarjan. Then because of the original writing if the diagram is not connected, it will be wrong, WA for a long time.
#include <cstdio> #include <stack> #include <cstring> #include <iostream> #include < algorithm>using namespace std; #define REP (i,n) for (int i=1;i<=n;i++) #define CLR (x,c) memset (x,c,sizeof (x)) # Define OP () pt=edges;clr (head,0); const int NMAX=50000;CONST int Maxn=200000;const int Inf=0x7f7f7f7f;int read () {int x=0; Char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} struct edge{int to,cap,id;edge *next,*rev;}; Edge Edges[maxn],*pt,*head[nmax],*p[nmax],*cur[nmax];int cnt[nmax],h[nmax],ans[60005][2],sccno[nmax],dfs_clock=0 , scc_cnt=0,pre[nmax];stack<int>s;void Add (int uu,int vv,int w,int x) {pt->to=vv;pt->cap=w;pt->id=x; pt->next=head[uu];head[uu]=pt++;} void Adde (int uu,int vv,int w,int x) {Add (uu,vv,w,x); add (vv,uu,0,-1); head[uu]->rev=head[vv];head[vv]->rev=head [UU];} int maxflow (int s,int t,int n) {clr (cnt,0); cnt[0]=n;clr (h,0); int Flow=0,a=inf,x=s;edge *e;while (h[s]<n) {for (e=cur[ X];e;e=e->next) if (e->cap>0&&h[x]==h[e->to]+1) Break;if (e) {a=min (a,e->cap);p [E->to]=cur[x]=e;x=e->to;if ( x==t) {while (x!=s) P[x]->cap-=a,p[x]->rev->cap+=a,x=p[x]->rev->to;flow+=a,a=inf;}} Else{if (!--cnt[h[x]]) break;h[x]=n;for (e=head[x];e;e=e->next) if (e->cap>0&&h[x]>h[e->to]+ 1) h[x]=h[e->to]+1,cur[x]=e;cnt[h[x]]++;if (x!=s) x=p[x]->rev->to;}} return flow;} int dfs (int x) {int lowu=pre[x]=++dfs_clock;s.push (x); for (Edge *e=head[x];e;e=e->next) if (e->cap>0) {int to= E->to;if (!pre[to]) lowu=min (Lowu,dfs (to)), else if (!sccno[to]) lowu=min (Lowu,pre[to]);} if (Lowu>=pre[x]) {scc_cnt++;while (1) {int x=s.top (); S.pop (); sccno[x]=scc_cnt;if (x==x) break;}} return LOWU;} int main () {/*freopen ("Data.out", "R", stdin), Freopen ("Orz.out", "w", stdout); */op (); int n=read (), M=read (), S=read (), t =read (), U,v,d;rep (i,m) U=read (), V=read (), D=read (), Adde (U,v,d,i), Maxflow (S,t,n), Rep (i,n) if (!pre[i]) DFS (i); Rep (I, N) {for (Edge *o=head[i];o;o=o->next) if (o->id>0&&!O->CAP) {if (Sccno[i]!=sccno[o->to]) ans[o->id][0]=1;if (sccno[i]==sccno[s]&&sccno[o- >to]==sccno[t]) ans[o->id][1]=1;}} Rep (i,n) printf ("%d:%d\n", I,sccno[i]),/*rep (i,m) {if (Sccno[u[i]]!=sccno[v[i])) printf ("1"), Else printf ("0"); Sccno[u[i]]==sccno[s]&&sccno[v[i]]==sccno[t]) printf ("1\n"), Else printf ("0\n");} */rep (i,m) printf ("%d%d\n", ans[i][0],ans[i][1]); return 0;}
1797: [Ahoi2009]mincut min cut time limit:10 Sec Memory limit:162 MB
submit:1812 solved:783
[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
[Submit] [Status] [Discuss]
bzoj1797: [Ahoi2009]mincut min cut