The main topic is:
K-Table milking machine, C cattle, K not more than 30,c not more than 200, each milking machine can work for M-cow, give these cows and machines, between the cow and the machine, the distance between the machines and machines, in order to ensure that the most cows have a machine milking the case, give the distance of the longest one of the cattle moving distance of the minimum value.
First use Floyd to find the shortest distance between any two points, and then use the dichotomy to limit the most moving distance d, when the maximum flow, the search for the augmented path at the same time also judge the distance is not more than D on the line.
1#include <cstdio>2#include <cstring>3#include <queue>4 #define_CLR (x, y) memset (x, y, sizeof (x))5 #defineMin (x, y) (x < y x:y)6 #defineINF 0x3f3f3f3f7 #defineN 10058 using namespacestd;9 Ten intFlow[n][n], dist[n][n]; One intLevel[n]; A intK, C, M, S, T, ln; - - voidFloyd () the { - for(intk=1; k<=ln; k++) - for(intI=1;i<=ln; i++)if(dist[i][k]<INF) - for(intj=1; j<=ln; J + +) + if(dist[i][k]+dist[k][j]<Dist[i][j]) -DIST[I][J] = dist[i][k]+Dist[k][j]; + } A at BOOLBFS () - { -_CLR (Level,-1); -Level[s] =0; -queue<int>Q; - Q.push (S); in while(!q.empty ()) - { to intU =Q.front (); + Q.pop (); - for(intI=0; i<=t; i++) the { * if(Flow[u][i] && level[i]<0) $ {Panax NotoginsengLevel[i] = Level[u] +1; - Q.push (i); the } + } A } the returnLevel[t]>0?1:0; + } - $ intDfsintXintf) $ { - intA; - if(x==t)returnF; the for(intI=0; i<=t; i++) - {Wuyi if(Flow[x][i] && level[i]==level[x]+1&& (a=Dfs (i,min (f,flow[x][i )))) the { -Flow[x][i]-=A; WuFLOW[I][X] + =A; - returnA; About } $ } -LEVEL[X] =-1; - return 0; - } A +__int64 Dinic (intlen) the { - //build a residual network $_CLR (Flow,0); the for(intI=1; i<=k; i++) theFlow[s][i] =M; the for(inti=k+1; i<=ln; i++) theFLOW[I][T] =1; - for(intI=1; i<=k; i++)//Machine in for(inti=h+1; j<=ln; J + +)//cows theFLOW[I][J] = (dist[i][j]<=len); the About //solving the maximum flow the__int64 ans=0, a=0; the while(BFS ()) the while(A=dfs (0, INF)) ans + =A; + returnans; - } the Bayi //The minimum solution satisfying the condition by two-part solution the intSlove () the { - intL=1, r=100000; - while(l<=R) the { the intMid = (l+r) >>1; the if(Dinic (mid) >=c) R = mid-1; the ElseL = mid+1; - } the returnl; the } the intMain ()94 { the while(~SCANF ("%d%d%d", &k, &c, &M)) the { theln = k +C;98T = ln +1; About_CLR (Dist,0); - for(intI=1; i<=ln; i++)101 for(intj=1; j<=ln; J + +)102 {103scanf"%d", dist[i]+j);104 if(dist[i][j]==0) dist[i][j]=INF; the }106 ////Find the shortest distances between entities107 Floyd ();108 109printf"%d\n", Slove ()); the }111 return 0; the}
POJ 2112 floyd+dinic Maximum flow + binary minimum