This is an example of a matching problem on a bipartite graph. This is much easier to solve than the travelling salesman problem and can be done in O((n+k)^3).
There are two subproblems:
- Find which people can reach each restaurant
- Find how to match people to restaurants to avoid overflowing the constraints
Reaching Restaurants
It is possible to compute the shortest path between any pair of points in O(n^3) by using, for example, the Floyd-Warshall algorithm.
The allowed matchings are then the connections of distance less than 1 km.
Matching people to restaurants
This matching problem can be solved by constructing a graph and then solving for the maximum flow.
An appropriate graph is to have a source node, a sink node, and a node for each person and each restaurant.
- Connect the source to each person with capacity 1
- Connect each person to each restaurant within 1km with capacity 1
- Connect each restaurant to the sink node with capacity Ceil(n/k).
Then compute the maximum flow through this graph. Every guest can be accomodated if and only if the maximum flow is n.
There are many algorithms to compute the maximum flow. One example would be push-relabel with complexity O(V^3) where V is the number of vertices (V=n+k+2 in this problem).