Test instructions
In a forward flow network, how many edges are satisfied to increase their traffic can increase the total flow.
Analysis:
First, the maximum flow is obtained, then the Yuanhui point is dyed along the edge of the stream, and the end is stained by the source point, and the edge head is counted by the sink point staining.
Code:
POJ 3204//sep 9#include <iostream> #include <queue> using namespace std; const int maxn=512; const int maxm=10024; struct Edge {int v,f,c,nxt; }E[MAXM*2+10]; Queue<int> que; int Src,sink,n,m;int g[maxn+10]; int nume; int vis[maxn+10]; int dist[maxn+10]; void Addedge (int u,int v,int c) {e[++nume].v=v;e[nume].f=c;e[nume].c=c;e[nume].nxt=g[u];g[u]=nume; E[++nume].v=u;e[nume].f=0;e[nume].c=c;e[nume].nxt=g[v];g[v]=nume; } void Init () {memset (g,0,sizeof (g)); nume=1; } void BFs () {while (!que.empty ()) Que.pop (); Vis[src]=true; Que.push (SRC); while (!que.empty ()) {int U=que.front (); Que.pop (); for (int i=g[u];i;i=e[i].nxt) if (e[i].f&&!vis[e[i].v]) {Que.push (E[I].V); dist[e[i].v]=dist[u]+1; Vis[e[i].v]=true; }}} int dfs (int u,int delta) {if (u==sink) return delta; InchT ret=0; for (int i=g[u];d elta&&i;i=e[i].nxt) if (e[i].f&&dist[e[i].v]==dist[u]+1) {int Dd=dfs ( E[i].v,min (E[i].f,delta)); E[I].F-=DD; E[I^1].F+=DD; DELTA-=DD; RET+=DD; } return ret; } int dinic () {int ret=0; while (1) {memset (vis,0,sizeof (VIS)); memset (dist,0,sizeof (Dist)); BFS (); if (!vis[sink]) break; Ret+=dfs (Src,int_max); } return ret; } int Min_cut () {memset (vis,0,sizeof (VIS)), while (!que.empty ()) Que.pop (); Que.push (SRC); Vis[src]=1;while (!que.empty ()) {int U=que.front (); Que.pop (); for (int i=g[u];i;i=e[i].nxt) {int v=e[i].v,f=e[i].f;if (!vis[v]&&f>0 &&i%2==0) {Vis[v]=1;que.push (v);}}} Que.push (sink); Vis[sink]=2;while (!que.empty ()) {int U=que.front (); Que.pop (); for (int i=g[u];i;i=e[i].nxt) {int v=e[i ].v,f=e[i].f;if (!vis[v]&&f<e[i].c&&i%2==1) {Vis[v]=2;que.push (v);}}} int Ans=0;for(int u=0;u<n;++u) for (int i=g[u];i;i=e[i].nxt) {int v=e[i].v,f=e[i].f;if (vis[u]==1&&vis[v]==2&&i %2==0) ++ans;} return ans;} int main () {while (scanf ("%d%d", &n,&m) ==2) {init (); while (m--) {int a,b,c;scanf ("%d%d%d", &a,&b,&c ); Addedge (a,b,c);} Src=0,sink=n-1;dinic ();p rintf ("%d\n", Min_cut ());} return 0;}
POJ 3204 Ikki ' s story i-road reconstruction Max Stream