2
void insert(const vector<string> &path) {5
if (!node->children.count(p)) {6
node->children[p] = make_unique<Trie>();8
node = node->children[p].get();11
map<string, unique_ptr<Trie>> children;17
map<string, Trie *> seen;18
unordered_set<Trie *> toDelete;20
string deduplicate(Trie *node) {22
for (auto &[s, n] : node->children) {23
path += s + deduplicate(n.get());25
if (path.empty()) return "";27
if (seen.count(path)) {28
toDelete.insert(seen[path]);29
toDelete.insert(node);33
return "(" + path + ")";36
void getPaths(Trie *node, vector<vector<string>> &paths, vector<string> &path) {37
for (auto &[s, n] : node->children) {38
if (toDelete.count(n.get())) continue;40
getPaths(n.get(), paths, path);44
if (!path.empty()) paths.push_back(path);48
vector<vector<string>> deleteDuplicateFolder(vector<vector<string>> &paths) {49
for (auto &path : paths) root.insert(path);52
getPaths(&root, paths, vector<string>() = {});