From a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Fri, 27 Jun 2025 12:23:02 -0600 Subject: chore: remove old cpp and rust solutions --- other/find_path_graph.rs | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 other/find_path_graph.rs (limited to 'other/find_path_graph.rs') diff --git a/other/find_path_graph.rs b/other/find_path_graph.rs deleted file mode 100644 index a74a654..0000000 --- a/other/find_path_graph.rs +++ /dev/null @@ -1,48 +0,0 @@ -struct Solution; - -impl Solution { - pub fn valid_path(n: i32, edges: Vec>, source: i32, destination: i32) -> bool { - let n: usize = n as usize; - let mut roots: Vec = { - let mut ans: Vec = vec![0; n]; - for i in 0..n { - ans[i] = i; - } - ans - }; - let mut ranks: Vec = vec![1; n]; - for e in edges { - let u = e[0] as usize; - let v = e[1] as usize; - Self::union(u, v, &mut roots, &mut ranks); - } - Self::find(source as usize, &mut roots) == Self::find(destination as usize, &mut roots) - } - fn union(x: usize, y: usize, roots: &mut Vec, ranks: &mut Vec) { - let (root_x, root_y) = (Self::find(x, roots), Self::find(y, roots)); - if root_x == root_y { - return; - } - if ranks[x] > ranks[y] { - roots[root_y] = root_x; - ranks[root_x] += 1; - } else { - roots[root_x] = root_y; - ranks[root_y] += 1; - } - } - fn find(x: usize, roots: &mut Vec) -> usize { - let mut x = x; - while x != roots[x] { - roots[x] = roots[roots[x]]; - x = roots[x]; - } - x - } -} - -fn main() { - let (n, source, destination) = (3, 0, 2); - let edges = vec![vec![0,1], vec![1,2], vec![2,0]]; - print!("{}", Solution::valid_path(n, edges, source, destination)); -} -- cgit v1.2.3