21. Shortest Path Using At Most One Curved Edge
β GFG solution to the Shortest Path Using At Most One Curved Edge problem: find minimum path length using Dijkstra with state tracking for curved edge usage. π
π§© Problem Description
π Examples
Example 1
Input: V = 4, E = 4, a = 1, b = 3, edges[][] = [[0, 1, 1, 4], [0, 2, 2, 4], [0, 3, 3, 1], [1, 3, 6, 5]]
Output: 2
Explanation:
Path 1 -> 0 -> 3 using straight edges costs 1 + 3 = 4.
But using the curved edge from 0 -> 3 gives 1 + 1 = 2, which is optimal.Example 2
Input: V = 2, E = 1, a = 0, b = 1, edges[][] = [[0, 1, 4, 1]]
Output: 1
Explanation:
Take the curved path from 0 to 1 which costs 1.π Constraints
β
My Approach
Dijkstra with State Tracking
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated