HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Single-source shortest paths with even weight

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
shortestsourcewithpathsweightsingleeven

Problem

I need help to find an algorithm that calculates the single-source shortest paths in a graph, with an extra condition that the weight of the path has to be even.
In another words, we have to find the shortest way with the minimum even weight.

I'd like to have some ideas how we solve this.

Thanks.

Solution

Forget the even-length requirement for a moment and consider how something like Dijkstra's algorithm works. As the algorithm progresses, you have essentially two types of vertex: the ones for which you've already figured out the shortest path, and the ones for which you only have an upper bound (i.e., the shortest path you've seen to that vertex so far).

Modify it so there are three types of vertex: ones for which you've figured out the shortest even-length path, ones for which you've figured out the shortest path but it was odd, and ones for which you only have an upper bound for the shortest path and shortest even path.

Context

StackExchange Computer Science Q#109481, answer score: 3

Revisions (0)

No revisions yet.