Complete the code to initialize the discovery time array in Tarjan's algorithm.
int[] disc = new int[n]; for (int i = 0; i < n; i++) { disc[i] = [1]; }
We initialize discovery times to -1 to mark nodes as unvisited.
Complete the code to update the low time of the current node in DFS.
low[u] = Math.Min(low[u], [1]);We update low[u] with the minimum low[v] of its neighbors to find back edges.
Fix the error in the condition to detect a bridge edge.
if (low[v] [1] disc[u]) { bridges.Add(new Tuple<int, int>(u, v)); }
A bridge is found when low[v] > disc[u], so the correct condition is low[v] > disc[u].
Fill both blanks to correctly perform DFS and update low and disc arrays.
disc[u] = low[u] = [1]; time++; foreach (int v in graph[u]) { if (disc[v] == -1) { parent[v] = u; DFS(v, graph, disc, low, parent, bridges, ref time); low[u] = Math.Min(low[u], [2]); } }
We set disc[u] and low[u] to current time, then update low[u] with low[v] after DFS call.
Fill all three blanks to correctly handle back edges in Tarjan's algorithm.
else if (v != [1]) { low[u] = Math.Min(low[u], [2]); // Back edge found if (low[u] == [3]) { // Do something } }
We check back edges by ignoring the parent, update low[u] with disc[v], and compare low[u] with disc[u].
