Tree + Hashing [C++ clean and clear Code]
idea is, we will calculate the hash of all the subtree and if the count of  hash value of any subtree is greater than 1, then will mark that subtree as not incl
idea is, we will calculate the hash of all the subtree and if the count of  hash value of any subtree is greater than 1, then will mark that subtree as not included.\n\n```\nconst int mod = 1e9 + 7;\nconst int p = 163;\nmap<string, int> id;\nmap<int, string> Rid;\nint sz;\nstruct Node{\n    map<int, Node*> child;\n    int hash, not_include;\n    int val;\n\n    Node(){\n        hash = 0;\n        not_include = 0;\n        val = -1;\n    }\n};\n\n\nvoid insert(Node *root, vector<string> a){\n    for(string s : a){\n        int idx = id[s];\n        if(!root -> child.count(idx)){\n            root -> child[idx] = new Node();\n        }\n        root = root -> child[idx];\n        root -> val = idx;\n    }\n}\n    \n    \nvoid pre(Node *root){\n    function<int(Node*)> dfs = [&](Node *root){\n        if(root == NULL){\n            return 0;\n        }\n        int h = 0;\n        for(auto [i, v] : root -> child){\n                h = ((h * 1ll * p)%mod + ((dfs(root -> child[i]) * 1ll * p)%mod + i + 1)%mod )%mod;\n        }\n        root -> hash = h;\n        return h;\n    };\n    dfs(root);\n}\n\n    \nvoid remove(Node *root){\n    map<int, int> fr;\n    function<void(Node*)> dfs = [&](Node *root){\n        if(root == NULL) return;\n        fr[root -> hash]++;\n        for(auto [i, v] : root -> child){\n            if(root -> child[i]){\n                dfs(root -> child[i]);\n            }\n        }\n    };\n    dfs(root);\n    function<void(Node*)> dfs2 = [&](Node* root){\n        if(root == NULL) return;\n        if(fr[root -> hash] > 1 && root -> hash){\n            root -> not_include = 1;\n            return;\n        }\n        for(auto [i, v] : root -> child){\n            if(root -> child[i]){\n                dfs2(root -> child[i]);\n            }\n        }\n    };\n    dfs2(root);\n}\n    \n    \nvector<vector<string>> collect(Node *root){\n    vector<vector<string>> res;\n    function<void(Node*, vector<string>)> dfs = [&](Node *root, vector<string> a){\n        if(root == NULL || root -> not_include) return;\n        if(a.size()){\n            res.push_back(a);\n        }\n        for(auto [i, v] : root -> child){\n            if(root -> child[i]){\n                vector<string> b = a;\n                b.push_back(Rid[root -> child[i] -> val]);\n                dfs(root -> child[i], b);\n            }\n        }\n    };\n    dfs(root, {});\n    return res;\n}\n    \n\n\n\nclass Solution {\npublic:\n    vector<vector<string>> deleteDuplicateFolder(vector<vector<string>>& paths) {\n        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n        id.clear();\n        Rid.clear();\n        int cnt = 1;\n        for(vector<string> v : paths){\n            for(string s : v){\n                if(!id.count(s)){\n                    id[s] = cnt;\n                    Rid[cnt] = s;\n                    cnt++;\n                }\n            }\n        }\n        sz = id.size() + 1;\n        Node *root = new Node();\n        for(vector<string> v : paths){\n            insert(root, v);\n        }\n        pre(root);\n        remove(root);\n        vector<vector<string>> res = collect(root);\n        return res;\n    }\n};\n```
[]