Optimal MilkingTime Limit: 4000/2000 ms (Java/Other) Memory Limit: 60000/30000 K (Java/Other) Total Submission (s): 5 Accepted Submission (s ): 2 Problem DescriptionFJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 <= C <= 200) cows. A set of paths of various lengths runs among the cows and the milking machines. the milking machine locations are named by ID Numbers 1 .. k; the cow locations are named by ID numbers K + 1 .. K + C. each milking point can "process" at most M (1 <= M <= 15) cows each day. write a program to find an assignment for each cow to some milking machine so that the distance the furthest-walking cow travels is minimized (and, of course, the milking machines are not overutilized ). at least one legal assignment is possible for all input da Ta sets. cows can traverse several paths on the way to their milking machine. input * Line 1: A single line with three space-separated integers: K, C, and M. * Lines 2 .....: Each of these K + C lines of K + C space-separated integers describes the distances between pairs of various entities. the input forms a mathematical matrix. line 2 tells the distances from milking machine 1 to each of the other enti Ties; line 3 tells the distances from machine 2 to each of the other entities, and so on. distances of entities directly connected by a path are positive integers no larger than 200. entities not directly connected by a path have a distance of 0. the distance from an entity to itself (I. e ., all numbers on the diagonal) is also given as 0. to keep the input lines of reasonable length, when K + C> 15, A row is broken into successive lines of 15 numbers and a potentially shorter line to finish up a row. each new row begins on its own line. outputA single line with a single integer that is the minimum possible total distance for the furthest walking cow. sample Input2 3 20 3 2 1 13 0 3 2 02 3 0 1 01 2 1 0 21 0 0 2 0 Sample Output2 question: the cow is going to the milk producing machine, each cow can only access one milk generator, each of which has a certain capacity. Ask what is the shortest path of the farthest ox. Train of Thought: floyd is used to find the shortest path. The second answer is the network stream solution. First, obtain the distance directly from the vertex. Select the upper bound of the outbound path as the upper bound of the binary path. (At the beginning, the upper bound of the two is wrong, and wa is used several times ). Edge building: The Source Vertex and niujian edge, the capacity is 1, the machine and the sink vertex are built, the capacity is the capacity of the machine. The distance between the ox and the machine is less than two points to build an edge. Sap determines whether it meets the requirements and changes the upper and lower bounds. The final output result is OK. The NE and head functions need to be re-initialized every time a second answer is re-built. I forgot at the beginning, o (begin □lead) o ...... [Cpp] # include <iostream> # include <algorithm> # include <cstdio> # include <cstring> # define max (a, B) (a)> (B )? (A) :( B) using namespace std; const int N = 420; const int M = 82000; const int INF = 99999999; int n; int gap [N], dis [N], pre [N], head [N], cur [N]; int map [N] [N]; int NE, NV; struct Node {int pos, next; int c;} E [M]; # define FF (I, NV) for (int I = 0; I <NV; I ++) int sap (int s, int t) {memset (dis, 0, sizeof (int) * (NV + 1); memset (gap, 0, sizeof (int) * (NV + 1 )); FF (I, NV) cur [I] = head [I]; int u = pre [s] = s, maxflow = 0; int Ug = INF; gap [0] = NV; while (dis [s] <NV) {loop: for (int & I = cur [u]; I! =-1; I = E [I]. next) {int v = E [I]. pos; if (E [I]. c & dis [u] = dis [v] + 1) {aug = min (aug, E [I]. c); pre [v] = u; u = v; if (v = t) {maxflow + = aug; for (u = pre [u]; v! = S; v = u, u = pre [u]) {E [cur [u]. c-= aug; E [cur [u] ^ 1]. c + = aug;} aug = INF;} goto loop;} if (-- gap [dis [u]) = 0) break; int mindis = NV; for (int I = head [u]; I! =-1; I = E [I]. next) {int v = E [I]. pos; if (E [I]. c & mindis> dis [v]) {cur [u] = I; mindis = dis [v] ;}} gap [dis [u] = mindis + 1] ++; u = pre [u];} return maxflow;} void addEdge (int u, int v, int c) {E [NE]. c = c; E [NE]. pos = v; E [NE]. next = head [u]; head [u] = NE ++; E [NE]. c = 0; E [NE]. pos = u; E [NE]. next = head [v]; head [v] = NE ++;} int ans; void floyed () {for (int k = 1; k <= n; k ++) for (int I = 1; I <= N; I ++) {if (map [I] [k]! = INF) {for (int j = 1; j <= n; j ++) {if (map [k] [j]! = INF & map [I] [j]> map [I] [k] + map [k] [j]) {map [I] [j] = map [I] [k] + map [k] [j]; ans = max (map [I] [j], ans) ;}}}} int main () {int k, c, m; while (cin >>k> c >> m) {ans =-1; n = k + c; for (int I = 1; I <= n; I ++) for (int j = 1; j <= n; j ++) {cin> map [I] [j]; // ans = max (ans, map [I] [j]); if (map [I] [j] = 0) map [I] [j] = INF;} floyed (); int low = 0, high = ans, mid; // The value of high should be the longest path between all vertices, instead of the maximum value in the initial period. // wa several times for this reason. ...... While (low <= high) {NE = 0; NV = k + c + 2; memset (head,-1, sizeof (head); mid = (low + high) /2; for (int I = 1; I <= k; I ++) addEdge (I, k + c + 1, m ); for (int I = k + 1; I <= k + c; I ++) addEdge (0, I, 1); for (int I = k + 1; I <= k + c; I ++) // create a edge between a ox and a machine for (int j = 1; j <= k; j ++) {if (map [I] [j] <= mid) addEdge (I, j, 1);} if (sap (0, k + c + 1) = c) // If the mid value meets the condition, the value can be reduced. High = mid-1; else low = mid + 1;} cout <low <endl;} return 0 ;} /* 2 3 2 0 3 1 1 3 0 3 2 0 2 3 0 1 0 1 1 2 0 2 1 0 0 2 0 */