C++ BFS Clean and Fastest Code (Beats 99.89% of Users)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N*M) \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N*M)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#pragma GCC optimize("03")\nstatic int __star = []{\n    ios_base::sync_with_stdio(0);\n    cin.tie(NULL),cout.tie(NULL);\n    return 0;\n}();\nclass Solution {\npublic:\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> adj(n);\n        vector<vector<int>> ans(n);\n        for(auto &i: edges)\n        {\n            adj[i[0]].push_back(i[1]);\n        }\n        for(int par=0;par<n;par++)\n        {\n            queue<int> q;\n            q.push(par);\n            while(!q.empty())\n            {\n                int f=q.front();\n                q.pop();\n                for(auto &child:adj[f])\n                {\n                    if(ans[child].size()==0||ans[child].back()!=par){\n                        ans[child].push_back(par);\n                        q.push(child);\n                    }\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'Graph', 'C++']