Complete the code to initialize the visited vector with false values.
let mut visited = [1][false; graph.len()];
The vec! macro with [value; size] creates a vector initialized with the value repeated size times. Here, vec![false; graph.len()] initializes the vector with false values.
Complete the code to mark the current node as visited in the DFS function.
visited[[1]] = true;We mark the current node as visited by setting visited[node] to true.
Fix the error in the condition to detect a cycle when a node is in the recursion stack.
if rec_stack[[1]] { return true; }
We check if the neighbor node is already in the recursion stack to detect a cycle.
Fill both blanks to complete the loop that iterates over neighbors of the current node.
for &[1] in graph[[2]].iter() {
The loop iterates over neighbors of the current node. We use 'neighbor' for each adjacent node and 'node' as the current node index.
Fill all three blanks to complete the recursive DFS call and update recursion stack.
rec_stack[[1]] = true; if dfs(graph, [2], visited, rec_stack) { return true; } rec_stack[[3]] = false;
We mark the neighbor as in recursion stack, call DFS on neighbor, and then remove neighbor from recursion stack after the call.
