Graph Theory37 sections · 1633 units
Open in Course

CSES 1202 Investigation - Update Rules

(When relaxing u→v)

If dist[u] + w < dist[v]:

  • Set dist[v] = dist[u] + w.
  • Set cnt[v] = cnt[u].
  • Set minEdges[v] = minEdges[u] + 11.
  • Set maxEdges[v] = maxEdges[u] + 11.

If dist[u] + w == dist[v]:

  • Add cnt[u] to cnt[v] (mod 109+710^9 + 7).
  • Update minEdges[v] = min(minEdges[v], minEdges[u] + 11).
  • Update maxEdges[v] = max(maxEdges[v], maxEdges[u] + 11).

The first case replaces the old path. The second case adds an alternative shortest path.