Search code examples
algorithmgraphnetwork-flow

Flow / Graph: Earliest date cities will be connected


Given N cities and M planned infrastructure projects, I need to find an approach to determine the earliest date at which two specific cities will be connected.

Some cities resides on the same island and can therefore be easily reached from each other. These cities form a community. There are C such communities.

Example input:

Communities consisting of cities:

  • Chesney, Bently, Dee
  • Immy, Caleigh, Kinley
  • Ady, Georgette, Elaina, Tanya

Planned infrastructure projects:

  • 2020-04-12: Tunnel between Bently and Kinley
  • 2021-01-04: Bridge between Dee and Kinley
  • 2021-07-01: Tunnel between Immy and Ady
  • 2021-10-12: Tunnel between Chesney and Georgette.

For example given the cities Chesney and Georgette, the earliest date in which these cities are connected is 2021-07-01.

I am thinking of two approaches that this problem can be modelled. Either as a graph problem, so it can be solved using an MST algorithm or by reducing it to a network flow. I see some remsebles to the Airline Scheduling problem, which can be solved using a network flow, which makes me think that this problem is more likely a network flow problem. However I am not quite sure how to model this specific problem as a network flow problem. Could someone guide me in the right direction?


Solution

  • You can solve this with Kruskal's algorithm, sorting the edges by completion date instead of weight.