- Let
G' = (V, E - E')
- Create
h + 1
copies ofG'
as G0, ... Gh - if
(u, v)
is a risky edge inG
, include a directed edge fromu
in Gi tov
in Gi+1 - Run Dijkstra's Algorithm from start vertex
s
. Now dijstraDistance(s, vi) represents shortest path froms
tov
in original graphG
using exactlyi
risky edges. - To calculate our solution (the distance from
s
tov
in original graphG
using at mosth
risky edges), we calculate: minimum0<=i<=h { dijkstraDistance(s, vi) }.
- Time Complexity: Dijkstra's algorithm is generally O(m + n log n), but since we have
mh
edges andnh
nodes, our complexity becomesO(mh + nh log (nh))
- Space Complexity:
O(mh + nh)
to createG'
Use the same algorithm as above, but instead of creating h + 1
copies of G'
, extend it to create hihj + 1 copies of G'
, where the hihj copy represents having traversed i
blue edges and j
red edges.
Same as above, but replace each h
with hihj