Challenge: Shortest Paths
Explore how to determine the best city for two travelers to meet by using shortest path algorithms in weighted graphs. Learn to implement Dijkstra's algorithm twice and combine results to find the minimal total travel time, enhancing your skills in graph algorithms with C++.
We'll cover the following...
Let's practice what we've learned so far.
Task
We just discovered our best friend from elementary school on Twitbook. We both want to meet as soon as possible, but we live in two different cites that are far apart. To minimize travel time, we agree to meet at an intermediate city, and then we simultaneously hop in our cars and start driving toward each other. But where exactly should we meet? We are given a weighted graph , where the vertices represent cities and the edges represent roads that directly connect cities. Each edge has a weight equal to the time required to travel between the two cities. We’re also given a vertex , representing our starting location, and a vertex , representing our friend’s starting location. To find the optimal meeting point for two people traveling along a weighted graph, we can use Dijkstra’s algorithm. We start by computing the shortest paths from both the starting vertices and to every other vertex in the graph. Then, we iterate through all the vertices in the graph and compute the sum of the shortest path ...