A one-way sign goes up near Galway. Can you still take the shortest route?
A junction near Galway gets a one-way sign. Your map still shows a short road, but can you actually take it? And when your route planner first finds a way to your destination, how does it know whether to keep looking?
On two-way roads, you can travel in either direction. Start with zero at A and infinity elsewhere. Make A permanent, giving B two and C seven. Next, make B permanent and add three to two. Five beats seven, so update C, then make C permanent.
From A, you can drive to B or straight to D. From B, you can drive to C, and from C to D. Now look at the arrow from E into B. When you process B, update only neighbours you can drive to from B. Those are its outgoing neighbours.
You've just made B permanent. The arrow from B to C points out of B, and the arrow from E to B points into B. Which neighbour should you consider updating from B? Pick one.
Label A zero and all other vertices infinity. Make A permanent. Its arrows give B two and D nine. B has the smallest tentative label, so make it permanent and give C four. Make C permanent next and lower D to five. Now make D permanent and stop.
Keep the arrows, but change the lengths. A to B is three kilometres, A to D is eight, B to C is one, and C to D is two. What label does D have when it becomes permanent? Pick an answer.
Stopping at nine misses the route through B and C. Dijkstra's greedy choice selects D at five, the smallest tentative label. On any shorter route, the first unsettled vertex would already have a smaller label from its permanent predecessor: with non-negative weights, the prefix is no longer than the full route.
Infinity means you haven't found a route to that vertex yet. Stopping at D alone doesn't prove that other vertices labelled infinity are unreachable. Here, E has no incoming arrow, so A can't reach it. In general, once no finite tentative labels remain, every vertex still at infinity is unreachable.
In dynamic programming, your state is your current vertex. Set D's distance to go to zero. Bellman's principle says the rest of a shortest route is also shortest. At each stage, minimise road length plus distance to go. Solve C, B, then A. The minimising choices give your optimal policy.