what a pity
i even do not know why?\n\n\n[edited]\nafter contest i got this\n\n\n\n\nclass Solution {\npublic:\n    vector<int> smallestMissingValueSubtree(const vector<int
i even do not know why?\n![image](https://assets.leetcode.com/users/images/a42545e8-5550-473b-ac71-a5072f4f9197_1631419289.2008238.png)\n\n[edited]\nafter contest i got this\n![image](https://assets.leetcode.com/users/images/7f4ca1b2-2c0f-4039-93d5-917b784ec5c1_1631419478.6917138.png)\n\n\n```\nclass Solution {\npublic:\n    vector<int> smallestMissingValueSubtree(const vector<int>& parents, const vector<int>& nums) {\n        int n = parents.size();\n        vector<int> degree(n, 0);\n        for (int i : parents) {\n            if (i != -1) ++degree[i];\n        }\n        vector<map<int, int>> all(n, map<int, int>());\n        queue<int> q;\n        for (int i = 0; i < n; ++i) {\n            if (degree[i] == 0) {\n                q.push(i);\n            }\n            all[i][nums[i]] = nums[i];\n        }\n        while (q.size()) {\n            int cur = q.front();\n            q.pop();\n            if (cur == 0) break;\n            merge(all[parents[cur]], all[cur]);\n            if (--degree[parents[cur]] == 0) {\n                q.push(parents[cur]);\n            }\n        }\n        vector<int> res(n);\n        for (int i = 0; i < n; ++i) {\n            res[i] = first(all[i]);\n        }\n        return res;\n    }\n\n    void merge(map<int, int>& dest, const map<int, int>& m) {\n        for (auto& p : m) {\n            auto ipos = dest.insert(p).first;\n            if (ipos != dest.begin()) {\n                auto pipos = prev(ipos);\n                if (pipos->second + 1 == ipos->first) {\n                    pipos->second = ipos->second;\n                    dest.erase(ipos);\n                    ipos = pipos;\n                }\n            }\n            if (auto nipos = next(ipos); nipos != dest.end()) {\n                if (ipos->second + 1 == nipos->first) {\n                    ipos->second = nipos->second;\n                    dest.erase(nipos);\n                }\n            }\n        }\n    }\n\n    int first(const map<int, int>& dest) {\n        if (auto p = dest.begin(); p->first == 1) {\n            return p->second + 1;\n        }\n        return 1;\n    }\n};\n```
[]