is one that asks for the smallest cut.
Sol
The data is large, n has 20000, the internal side of the connection has 20w, so calculate to save eight hundred thousand or nine hundred thousand of the side, the space obviously can't fall down ... However, playing dinic does not feel much faster ... Run to the 3800+ms.
Then kneel a big Uncle 2000ms, he only opened 50w side this is how to do qwq ... And then there's no significant difference. He was sealed in a class (I didn't know that this thing only knew the same struct) ... is reading into the optimization of playing ugly ...
Attach his code address: http://acm.hust.edu.cn/vjudge/problem/viewSource.action?id=4433085
Code:
/*==========================================================================# last modified:2016-03-07 19:49# filename:poj3469.cpp# Description: ==========================================================================*/# Define me Acrossthesky #include <cstdio> #include <cmath> #include <ctime> #include <string> #inc (in) Lude <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #define LOWBIT (x) (x) & (-X ) #define for (I,A,B) for ((i) = (a);(i) <= (b);(i) + +) #define FORP (I,A,B) for (int i= (a); i<= (b); i++) #define FORM (i,a,b ) for (int i= (a); i>= (b); i--) #define LS (A, a) (((a) + (b)) << 1) #define RS (A, B) (((a) + (c)) >> 1) #define GETLC (a) ch[(a)][0] #define GETRC (a) ch[(a)][1] #define MAXN 20015#define maxm 1000500 #define PI 3.1415926535898 #define _E 2 .718281828459 #define INF 1070000000 using NAMESPAce STD; typedef long Long LL; typedef unsigned long long ull; Template<class t> inline void read (t& num) {bool start=false,neg=false; char c; num=0; while ((C=getchar ())!=eof) {if (c== '-') start=neg=true; else if (c>= ' 0 ' && c<= ' 9 ') {start=true; num=num*10+c-' 0 '; } else if (start) break; } if (neg) num=-num; }/*==================split line==================*/int s,t,n,m;int sume=1;struct edge{int from,to,cap;} E[maxm];int first[maxn],d[maxn],next[maxm],cur[maxn];bool vis[maxn];queue<int> q;void addedge (int x,int y,int CAP) {sume++; e[sume].from=x; e[sume].to=y; e[sume].cap=cap;next[sume]=first[x]; first[x]=sume;sume++; e[sume].from= Y E[sume].to=x; E[sume].cap=0;next[sume]=first[y]; First[y]=sume;} int BFs () {for (int i=s;i<=t;i++) Vis[i]=false;q.push (0); d[0]=0; Vis[0]=true;while (!q.empty ()) {int Now=q.front (); Q.pop (); for (int i=first[now];i;i=next[i]) if (!vis[e[i].to] && E[i]. cap) {D[e[i].to]=d[now]+1;vis[e[i].to]=true;q.push (e[i].to);}} return vis[t];} int dfs (int now,int a) {if (now==t | |!a) return a;int f,flow=0;for (int & i=cur[now];i;i=next[i]) if (D[now]+1==d[e[i]. To] && (F=dfs (E[i].to,min (a,e[i].cap)) >0) {flow+=f, a-=f; e[i].cap-=f; e[i^1].cap+=f;if (!a) break;} return flow;} int dinic () {int flow=0;while (BFS ()) {Forp (i,0,n) Cur[i]=first[i];flow+=dfs (S,inf);} return flow;} int main () {read (n); read (m); Forp (i,1,n) {int x;read (x); Addedge (0,i,x); read (x); Addedge (i,n+1,x);} Forp (i,1,m) {int x, z; read (×); Read (y); read (z); Addedge (x, y, z); Addedge (y,x,z);} s=0,t=n+1;printf ("%d", Dinic ());}
POJ3469 & min Cut (maximum flow) template