Explore Library
Code QuizAdvanced

Dijkstra Relaxation Drops Edge Weight

The relaxation step updates a distance without adding the edge weight.

Codejavascript
function relax(u, v, weight, dist, prev) {
  if (dist[u] + weight < dist[v]) {
    dist[v] = dist[u];
    prev[v] = u;
  }
}

The computed shortest distances are too small. What is the bug?