simplify bridge-searching expression #1460
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
current expression:
proposed expression:
We can further improve the intuition behind the
low[]
array. We know thatlow[node]
stores the lowest entry time of any node that is reachable fromnode
, including via back edges. Thetin[node]
represents the time whennode
was first discovered during DFS.When we encounter a back-edge from
node
to one of its ancestors (sayancestor
), the earlier logic suggests we considertin[ancestor]
to updatelow[node]
. However, we can simplify and strengthen this by observing that ifancestor
can reach further up in the DFS tree (through its own back-edges), we can directly uselow[ancestor]
instead.So instead of:
We use:
This works because
low[ancestor]
already reflects the lowest reachable ancestor forancestor
, and sincenode
can reachancestor
, it can also reach everything thatancestor
can.This simplification helps propagate the true lowest entry time more effectively through the DFS tree and back-edges.
Thus, the final update rule becomes:
for all adjacent
to
, whether they are descendants in the DFS tree or already visited ancestors (i.e., back-edges).