Run the network stream first, then Tarjan in the remaining network.
Consider an edge (U,V):
When and only if scc[u]! = Scc[v], (u,v) may appear in the smallest cut ... But I'm not going to prove
When and only if scc[u] = Scc[s] && scc[v] = = Scc[t], (U, v) must appear in the smallest cut. This is a good brain tonic, if this side is not full flow, then s-t there is an augmented road.
------------------------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <stack>using namespace std;const int MAXN = 4009;const int MAXM = 60009;const int INF = 10000000;struct Edge {int to, ID, cap;Edge *next, *rev;} E[MAXM << 1], *head[maxn], *pt = E; inline void Add (int u, int v, int w, int id) {pt->to = v; pt->cap = w; pt->id = ID;pt->next = Head[u]; Head[u] = pt++;}inline void Addedge (int u, int v, int w, int id) {Add (U, V, W, id), add (V, u, 0,-1);Head[u]->rev = head[v];Head[v]->rev = Head[u];}Edge *P[MAXN], *CUR[MAXN];int H[MAXN], CNT[MAXN], ans[maxm][2], N, S, T;stack<int> STA;int DFN[MAXN], LOW[MAXN], scc[maxn], CK = 0, n = 0;void Maxflow () {memset (h, 0, sizeof h);memset (CNT, 0, sizeof CNT);for (int i = 0; i < N; i++) cur[i] = Head[i];cnt[0] = N;edge* E;for (int x = S, A = INF; H[s] < N;) {For (e = cur[x]; e; e = e->next)if (e->cap && h[e->to] + 1 = = H[x]) break;if (e) {a = min (A, e->cap);P[e->to] = cur[x] = e;x = e->to;if (x = = T) {For (; x! = S; x = p[x]->rev->to) {P[x]->cap-= A;P[x]->rev->cap + = A;}A = INF;x = S;}} else {if (!--Cnt[h[x]]) break;h[x] = N;For (e = head[x]; e = e->next) if (H[e->to] + 1 < h[x] && e->cap) {h[x] = h[e->to] + 1;cur[x] = e;}++cnt[h[x]];if (x! = S) x = p[x]->rev->to;}}}void Tarjan (int x) {dfn[x] = low[x] = ck++;Sta.push (x);For (edge* e = head[x]; e; e = e->next) if (e->cap) {if (!~dfn[e->to])Tarjan (e->to), low[x] = min (low[x], low[e->to]);else if (!~scc[e->to])low[x] = min (low[x], dfn[e->to]);}if (dfn[x] = = Low[x]) {int t;Do {t = sta.top (); Sta.pop ();scc[t] = n;} while (t! = x);n++;}}int main () {int m;scanf ("%d%d%d%d", &n, &m, &s, &t); s--; t--;for (int i = 0; i < m; i++) {int U, V, c; scanf ("%d%d%d", &u, &v, &c); u--; v--;Addedge (U, V, c, i);}Maxflow ();memset (DFN,-1, sizeof DFN);memset (Low,-1, sizeof low);memset (SCC,-1, sizeof SCC);for (int i = 0; i < N; i++) if (!~dfn[i]) Tarjan (i);for (int i = 0; i < N; i++)For (edge* e = head[i]; e; e = e->next) if (~e->id &&!e->cap) {if (scc[i]! = Scc[e->to]) ans[e->id][0] = 1;if (scc[i] = = Scc[s] && scc[e->to] = = Scc[t]) ans[e->id][1] = 1; }for (int i = 0; i < m; i++)printf ("%d%d\n", ans[i][0], ans[i][1]);return 0;}
------------------------------------------------------------------------------------
1797: [Ahoi2009]mincut min cut Time Limit:Ten Sec Memory Limit:162 MB
Submit:1476 Solved:624
[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 Input 6 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 Output 1 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
Bzoj 1797: [Ahoi2009]mincut min cut (Network stream)