Topic: Given a map, each edge of a limited number of times a day, a person can only pass one side each day, T individual from point 1th, ask how many days to reach N points
Layers the graph, each day as a layer, each layer of points down a layer of connected edge
1th points to the No. 0 level from the source point to the Edge
The edge of the N-to T-link inf for each layer
Enumerate the days starting from 1, build one more layer per day and run the maximum stream, and if the current T-person has reached point n, output the answer
Because the path length of the 1~n does not exceed N, the total number of days that the T individual queues this path will not exceed T+n
So only need to build n+t layer can be out of the number O (n^2+nt) Edge O (MN+MT) is not very big can run out
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 5010# Define S 0#define T (M-1) #define INF 0x3f3f3f3fusing namespace std;struct edge{int x, Y, Z;} Edges[m];int n,m,t;namespace max_flow{struct abcd{int to,f,next;} Table[1001001];int head[m],tot=1;int dpt[m];void Add (int x,int y,int z) {Table[++tot].to=y;table[tot].f=z;table[tot]. Next=head[x];head[x]=tot;} void Link (int x,int y,int z) {Add (x, y, z); ADD (y,x,0);} BOOL BFS () {static int q[m];int i,r=0,h=0;memset (dpt,-1,sizeof DPT);DP t[s]=1;q[++r]=s;while (r!=h) {int x=q[++h];for (i= Head[x];i;i=table[i].next) if (table[i].f&&!~dpt[table[i].to]) {Dpt[table[i].to]=dpt[x]+1;q[++r]=table[i] . To;if (Table[i].to==t) return true;}} return false;} int dinic (int x,int flow) {int i,left=flow;if (x==t) return flow;for (I=head[x];i&&left;i=table[i].next) if ( table[i].f&&dpt[table[i].to]==dpt[x]+1) {int temp=dinic (table[i].to,min (LEFT,TABLE[I].F)); left-=temp; Table[i].f-=temp;table[i^1].f+=temp;} if (lEFT) Dpt[x]=-1;return Flow-left;}} int main () {using namespace Max_flow;int i,j,x,y,z;cin>>n>>m>>t;for (i=1;i<=m;i++) {scanf ("%d%d% D ", &x,&y,&z); edges[i].x=x;edges[i].y=y;edges[i].z=z;} int temp=0; Link (s,1,t), for (i=1;i<=n+t;i++) {for (j=1;j<=m;j++) Link (i*n-n+edges[j].x,i*n+edges[j].y,edges[j].z), for (j= 1;j<=n;j++) Link (I*n-n+j,i*n+j,inf); Link (I*n+n,t,inf), while (BFS ()) Temp+=dinic (S,inf), if (temp==t) return cout<<i<<endl,0;} return 0;} Point x:i*n+x of day I
Bzoj 1570 JSOI2008 Blue Mary's Travel network stream