🛤️ Beginner-Friendly Guide 'Minimum Cost Path with Edge Reversals' - LeetCode 3650 (C++, Python, JavaScript)
dev.to·3d·
Discuss: DEV
🕸️Graph Theory
Preview
Report Post

Navigating a graph is usually a one-way street, but what if you could briefly flip the direction of traffic to reach your destination? This problem challenges us to find the most efficient route when we have the special ability to reverse edges at a specific cost. It is a fantastic way to learn how to adapt classic shortest-path algorithms to handle unconventional rules.


You’re given:

  • A directed graph with nodes and a list of weighted edges.
  • A special "switch" at each node that allows you to reverse one incoming edge once you arrive there.
  • A cost rule: traversing a normal edge costs , while traversing a reversed edge costs .

Your goal:

Find the minimum total cost to travel from node 0 to node . If the destination is unreachable, return -1.

Example:

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help