c++ | easy | short
\n\n# Code\n\nstruct Node {\n    string name;\n    map<string, Node*> next; \n    bool del = false;\n    Node(string n = "") : name(n) {}\n};\nclass Solution {\
\n\n# Code\n```\nstruct Node {\n    string name;\n    map<string, Node*> next; \n    bool del = false;\n    Node(string n = "") : name(n) {}\n};\nclass Solution {\n    void addPath(Node *node, vector<string> &path) { \n        for (auto &s : path) {\n            if (node->next.count(s) == 0) node->next[s] = new Node(s);\n            node = node->next[s];\n        }\n    }\n    unordered_map<string, Node*> seen; \n    string dedupe(Node *node) { \n        string subfolder;\n        for (auto &[name, next] : node->next) {\n            subfolder += dedupe(next);\n        }\n        if (subfolder.size()) { \n            if (seen.count(subfolder)) { \n                seen[subfolder]->del = node->del = true;\n            } else {\n                seen[subfolder] = node;\n            }\n        }\n        return "(" + node->name + subfolder + ")"; \n    }\n    vector<vector<string>> ans;\n    vector<string> path;\n    void getPath(Node *node) {\n        if (node->del) return; \n        path.push_back(node->name);\n        ans.push_back(path);\n        for (auto &[name, next] : node->next) {\n            getPath(next);\n        }\n        path.pop_back();\n    }\npublic:\n    vector<vector<string>> deleteDuplicateFolder(vector<vector<string>>& A) {\n        Node root;\n        for (auto &path : A) addPath(&root, path);\n        dedupe(&root);\n        for (auto &[name, next] : root.next) getPath(next);\n        return ans;\n    }\n};\n```
['C++']