简体   繁体   中英

Finding the "fairest" meeting point in an undirected weighted graph

Given an undirected weighted graph, a start node and an end node, is there a way to (without using brute force) find a meeting point in between the start and end nodes such that:

the difference between 1) the distance from start to meeting point and 2) the distance from end to meeting point

is minimized?

I cant seem to think of any way to do this without using brute force.

Thank you

Just launch Dijkstra's algorithm to find distances to all nodes from the start node, then from the end node. Then find a node for which a difference between calculated distances is minimized.

You can use Dijkstra's algorithm, starting from both end and start nodes at the same time -- so using one priority queue. Just add as extra information to each node in the queue, whether you reached it from the start or from the end node. When you reach a node that was already visited, check whether it was visited from the "other" side (using that extra information): if so, stop the algorithm, and add up the two distances; the one you had registered on the first visit, and the one of your current, second visit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM