4 ms·
> you can trivially compute routes from N to M places using N Dijkstra runs to do even better, you can compute the shortest path & distance to M kebab shops fr
by shoo 2y ago
> you can trivially compute routes from N to M places using N Dijkstra runs
to do even better, you can compute the shortest path & distance to M kebab shops from the nearest of N train stations using a single run of a standard shortest path algorithm like Dijkstra, by changing the initial condition of the search to start from a set of multiple source nodes, not a single source node.
another way to think about this is to take the graph and augment it with an additional virtual root node and add length 0 edges from that virtual root node to each of the N train stations, then use that virtual root node as the source for a single-source Dijkstra.
alternatively, modify the original graph by merging all the train station nodes together into one node (if this introduces self-loop edges, delete them, if this introduces multi-edges between same pair of nodes, delete all but a minimal length one)