Rust beats 100%
Rust beats 100%\n\n\n# Code\n\nimpl Solution {\n    pub fn critical_connections(n: i32, connections: Vec<Vec<i32>>) -> Vec<Vec<i32>> {\n        let v = connecti
Rust beats 100%\n\n![image.png](https://assets.leetcode.com/users/images/40fa5005-56b4-4515-bf8b-cbc406b3949b_1716291929.9661348.png)\n# Code\n```\nimpl Solution {\n    pub fn critical_connections(n: i32, connections: Vec<Vec<i32>>) -> Vec<Vec<i32>> {\n        let v = connections[0][0];\n\n        let mut adj_list = vec![vec![]; n as usize];\n        for c in connections {\n            adj_list[c[1] as usize].push(c[0]);\n            adj_list[c[0] as usize].push(c[1]);\n        }\n\n        let mut rez = vec![];\n        Self::dfs(\n            v,\n            &mut vec![0; n as usize],\n            &mut adj_list,\n            &mut rez,\n        );\n        rez\n    }\n\n    fn dfs(\n        v: i32,\n        visited: &mut Vec<u32>,\n        adj_list: &mut Vec<Vec<i32>>,\n        rez: &mut Vec<Vec<i32>>,\n    ) -> u32 {\n        let mut total_collisions = 0;\n\n        visited[v as usize] = 1;\n        for u in std::mem::take(&mut adj_list[v as usize]) {\n            if visited[u as usize] != 0 {\n                visited[u as usize] += 1;\n                total_collisions += 1;\n                continue;\n            }\n            let collisions = Self::dfs(u, visited, adj_list, rez);\n            if collisions == 1 {\n                rez.push(vec![v, u]);\n            }\n            total_collisions += collisions + 1 - visited[v as usize];\n            visited[v as usize] = 1;\n        }\n        visited[v as usize] = 0;\n        total_collisions\n    }\n}\n```
['Rust']