Just a runnable solution
Code\n\nuse std::cell::RefCell;\nuse std::collections::BTreeMap;\nuse std::rc::Rc;\n\n#[derive(Debug, Clone, PartialEq, Eq)]\nstruct Node {\n    name: String,\n
# Code\n```\nuse std::cell::RefCell;\nuse std::collections::BTreeMap;\nuse std::rc::Rc;\n\n#[derive(Debug, Clone, PartialEq, Eq)]\nstruct Node {\n    name: String,\n    next: BTreeMap<String, Option<Rc<RefCell<Node>>>>,\n    del: bool,\n}\n\nimpl Node {\n    fn new(name: String) -> Self {\n        Self {\n            name,\n            next: BTreeMap::new(),\n            del: false,\n        }\n    }\n}\n\nimpl Solution {\n    pub fn delete_duplicate_folder(paths: Vec<Vec<String>>) -> Vec<Vec<String>> {\n        let mut ans = vec![];\n        let root = Some(Rc::new(RefCell::new(Node::new("".to_string()))));\n        for path in paths {\n            Self::add_path(root.clone(), path);\n        }\n        let mut seen = BTreeMap::new();\n        Self::dedupe(root.clone(), &mut seen);\n\n        let mut path = vec![];\n        for (_, next) in root.as_ref().unwrap().borrow().next.iter() {\n            Self::get_path(next.clone(), &mut ans, &mut path);\n        }\n\n        ans\n    }\n\n    fn add_path(mut node: Option<Rc<RefCell<Node>>>, path: Vec<String>) {\n        for s in path {\n            if node.as_ref().unwrap().borrow().next.get(&s).is_none() {\n                node.as_mut()\n                    .unwrap()\n                    .borrow_mut()\n                    .next\n                    .insert(s.clone(), Some(Rc::new(RefCell::new(Node::new(s.clone())))));\n            }\n            let tmp = node.as_ref().unwrap().borrow().next.get(&s).unwrap().clone();\n            node = tmp;\n        }\n    }\n\n    fn dedupe(mut node: Option<Rc<RefCell<Node>>>, seen: &mut BTreeMap<String, Option<Rc<RefCell<Node>>>>) -> String {\n        let mut subfolder = String::new();\n        for (_, next) in node.as_ref().unwrap().borrow().next.iter() {\n            subfolder += &Self::dedupe(next.clone(), seen);\n        }\n        if !subfolder.is_empty() {\n            if seen.contains_key(&subfolder) {\n                seen.get_mut(&subfolder).unwrap().as_mut().unwrap().borrow_mut().del = true;\n                node.as_mut().unwrap().borrow_mut().del = true;\n            } else {\n                seen.insert(subfolder.clone(), node.clone());\n            }\n        }\n        format!("({}{})", node.as_ref().unwrap().borrow().name, subfolder)\n    }\n\n    fn get_path(node: Option<Rc<RefCell<Node>>>, ans: &mut Vec<Vec<String>>, path: &mut Vec<String>) {\n        if node.as_ref().unwrap().borrow().del {\n            return;\n        }\n        path.push(node.as_ref().unwrap().borrow().name.clone());\n        ans.push(path.clone());\n        for (_, next) in node.as_ref().unwrap().borrow().next.iter() {\n            Self::get_path(next.clone(), ans, path);\n        }\n        path.pop();\n    }\n}\n\n```
['Rust']