Poj21_optimal Milking (the best Milking solution) -- floyd + maximum stream + second

Source: Internet
Author: User

Poj21_optimal Milking (the best Milking solution) -- floyd + maximum stream + second

 

Description:
Farmer John transported his K (1 ≤ K ≤ 30) Milk runners to the farm, where there were C (1 ≤ C ≤ 200) cows in the milk
There is a set of different lengths between the cool and the cool. 1 ~ The number of K indicates that the position of the cow is K + 1 ~
ID of K + C.
Each milking machine can milk a maximum of 1 (1 ≤ M ≤ 15) cows per day.
Write a program, find a solution, arrange each cow to a milking machine, and make all C cows need to go
The maximum distance is the least. Each test data contains at least one plan. Each cow has multiple routes to the milking machine.

Input description:
The format of the test data is as follows:
1st behavior: Three integers K, C, and M.
2nd ~ In rows K + C + 1, each line has K + C integers, which describe the position between the cow and the milk extruder (both collectively known as entities,
The K + C lines form a matrix symmetric along the diagonal line. The second line describes the distance between 2nd milk runners and other entities ,...,
The K + 1 line describes the distance between the K milk runners and other entities. The K + 2 line describes the distance between 1st cows and other entities.
,.... These distances are positive numbers not greater than 200. If there is no direct path between objects, the distance is 0. Entity and
The distance (an integer on the diagonal line) is also 0.

Output description:
Output an integer to the minimum value of the maximum distance that C cows need to walk in all solutions.

Because the question requires the largest and smallest in the path, floyd is used to obtain the shortest path between any two points. Then, the maximum edge of the two enumeration is obtained. Based on the premise restrictions of the maximum edge enumerated, a graph is created, the capacity from the source point to each dairy cow is 1, and the capacity of each Milk Station to the sink point is M. If the distance from a dairy cow to the dairy station is less than or equal to the maximum edge enumerated, the capacity is 1, determine whether the maximum stream is equal to C

#include
  
   #include
   
    #include
    
     #include
     
      #define REP(i,n) for(int i=0;i<(n);++i)#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define FORD(i,a,b) for(int i=(a);i<=(b);++i)const int maxn=250;const int INF=1<<30;using namespace std;int n,s,t;int K,C,M;struct Edge{    int from,to,cap,flow;    Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f){}};vector
      
        edges;vector
       
         G[maxn];int gap[maxn],d[maxn],cur[maxn],p[maxn];inline void addedge(int u,int v,int c){ edges.push_back(Edge(u,v,c,0)); edges.push_back(Edge(v,u,0,0)); int m=edges.size(); G[u].push_back(m-2); G[v].push_back(m-1);}int ISAP(){ s=0,t=n; memset(cur,0,sizeof(cur)); memset(d,0,sizeof(d)); memset(gap,0,sizeof(gap)); int x=s,flow=0,a=INF; while(d[s]
        
         e.flow&&d[e.to]+1==d[x]){ p[e.to]=G[x][i]; cur[x]=i; x=e.to; ok=1; a=min(a,e.cap-e.flow); break; } } if(!ok){ int m=n; for(int i=0;i
         
          e.flow) m=min(m,d[e.to]); } if(--gap[d[x]]==0) break; gap[d[x]=m+1]++; cur[x]=0; if(x!=s) x=edges[p[x]].from; } } return flow;}int g[maxn][maxn];int maxh,maxedge;void floyd(){ maxh=-1; FORD(k,1,n)FORD(i,1,n){ if(g[i][k]
          
           >K>>C>>M; n=K+C; FORD(i,1,n)FORD(j,1,n){ scanf(%d,&g[i][j]); if(g[i][j]==0) g[i][j]=INF; } floyd(); n+=2; int maxflow; int l=0,r=maxh; while(l
           
            >1; build(mid); maxflow=ISAP(); cout<
            
             =C) r=mid; else l=mid+1; } build(r); cout<
             
            
           
          
         
        
       
      
     
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.