Graph Theory37 sections · 1633 units
Open in Course

CSES 1195 Flight Discount - Transitions

(Two types of edges)

Starting at state (u, 00), you have two choices:

1.1. Take edge u→v at full cost: move to state (v, 00).

2.2. Use coupon on edge u→v: move to state (v, 11) at half cost. Starting at state (u, 11), you have one choice:

1.1. Take edge u→v at full cost: move to state (v, 11).

This gives you 2N2N nodes and up to 3M3M edges in the state graph. Run standard Dijkstra on this expanded graph. The answer is min(dist[(N,0)], dist[(N,1)]).