Complete the code to initialize the discovery time for the current node in Tarjan's algorithm.
disc[u] = [1]In Tarjan's algorithm, the discovery time of a node is set to the current time counter.
Complete the code to update the low time of the current node after visiting a neighbor.
low[u] = min(low[u], [1])
The low time of a node is updated with the minimum low time of its neighbors.
Fix the error in the condition that detects a bridge edge in Tarjan's algorithm.
if low[v] [1] disc[u]: bridges.append((u, v))
A bridge is found if the low time of neighbor v is greater than the discovery time of u.
Fill both blanks to correctly skip the parent node and update low time for back edges.
for v in graph[u]: if v == [1]: continue if disc[v] == -1: dfs(v, u) low[u] = min(low[u], [2])
We skip the parent node to avoid revisiting the edge we came from. After DFS, update low[u] with low[v].
Fill all three blanks to complete the DFS function header and the initial call.
def dfs([1], [2]): global time # disc and low initialized outside to -1 # ... rest of DFS body # Initialize and start # disc = [-1] * n # low = [-1] * n time = 0 dfs([3], -1)
The DFS function takes current node u and its parent. Arrays disc and low are initialized outside. Start by calling dfs(start, -1) where start is the starting node (e.g., 0).
