3. What will be the output of the following Rust code snippet detecting cycle in an undirected graph?
fn dfs(node: usize, parent: usize, graph: &Vec, visited: &mut Vec<bool>) -> bool {
visited[node] = true;
for &neighbor in &graph[node] {
if !visited[neighbor] {
if dfs(neighbor, node, graph, visited) {
return true;
}
} else if neighbor != parent {
return true;
}
}
false
}
fn main() {
let mut graph = vec![vec![]; 4];
graph[0].push(1); graph[1].push(0);
graph[1].push(2); graph[2].push(1);
graph[2].push(3); graph[3].push(2);
graph[3].push(1); graph[1].push(3);
let mut visited = vec![false; 4];
let has_cycle = dfs(0, usize::MAX, &graph, &mut visited);
println!("{}", has_cycle);
}