Why does this(Input: [[2,3],[5,2],[1,5],[4,2],[4,1]] Output: [4,2] Expected: [4,1] ) happens?
@administrators \n@contributors \nAs the title says, my solution is not accepted. Why does this happen? I think we should remove [4,2] as my solution. What is w
@administrators \n@contributors \nAs the title says, my solution is not accepted. Why does this happen? I think we should remove [4,2] as my solution. What is wrong?\n\nInput: [[2,3],[5,2],[1,5],[4,2],[4,1]]\nOutput: [4,2]\nExpected: [4,1]\n\n```\nclass Solution {\npublic:\n    vector<int> findRedundantConnection(vector<vector<int>>& edges) {\n        map<int, int> parent;\n        for (auto e : edges) {\n            if (parent.find(e[1]) != parent.end()) {\n                return e; \n            }\n            if (parent.find(e[0]) != parent.end()) {\n                if (parent[e[0]] == e[1])\n                    return e;\n            }\n            parent[e[1]] = e[0];\n        } \n        set<int> root;\n        for (auto e : edges) {\n            if (root.find(e[1]) != root.end())\n                return e;\n            root.insert(e[0]);\n        }\n        return edges.back();\n    }\n};\n```
[]