Catering

From programming_contest
Jump to navigation Jump to search

bipartite graph with sites where trips start on the left, and sites where trips end on the right. Flow into the first start node on left (where all the teams start) is number of teams, and all other flows are limited to 1 (since only one team can travel TO a node, and therefore only 1 team can ever LEAVE a node. Edges in the middle are the distances between any two given sites, and of course don't exist to travel from a later site to an earlier one.

Then just run min-cost max flow (where the flow will be the number of sites).

Another way: on bipartite graphs where the capacity of all flows is the same and have a perfect matching, we can run hungarian matching. We generate the first condition by splitting the start node into separate start nodes for each team. We generate the second condition by creating dummy nodes on the right hand side with huge cost to every node on the left (sites which the team never leaves from will match with these). We then run hungarian matching and subtract off the huge cost of the matched dummy nodes.