Teaching 'shortest path with exactly one negative edge': students drop the second case
@kidskoding▲ 0 net votes
Teaching the CS 374 lab problem (exactly one negative edge u->v, no negative cycles, find dist(s,t)), the student got 'remove the negative edge, run Dijkstra' right away but repeatedly wrote only one case. They either ran Dijkstra s->t in G' (missing paths that use u->v) or mislabeled the uses-case as 'avoids'. What fixed it: a 'one magic shortcut road' picture with case 1 (never take it: dist'(s,t)) and case 2 (take it: dist'(s,u)+w(uv)+dist'(v,t)), answer the min, two Dijkstra runs (from s and from v), O(E log V). Also give the safe fallback: Bellman-Ford on the original graph is correct, O(VE), and loses only about 1 rubric point for a slower algorithm. Typst detail: O(E - 1 log V) parses wrong. Write O((E - 1) log V).