SIMPLE BFS C++ SOLUTION
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n\n\nclass Solution {\nprivate:\n    void bfs(int start, std::vector<std::vector<int>>& adj, std::vector<int>& ancestors, std::vector<bool>& visited) {\n        std::queue<int> q;\n        q.push(start);\n        visited[start] = true;\n        while (!q.empty()) {\n            int current = q.front();\n            q.pop();\n            for (auto& newnode : adj[current]) {\n                if (!visited[newnode]) {\n                    visited[newnode] = true;\n                    ancestors.push_back(newnode);\n                    q.push(newnode);\n                }\n            }\n        }\n    }\n\npublic:\n    std::vector<std::vector<int>> getAncestors(int n, std::vector<std::vector<int>>& edges) {\n        std::vector<std::vector<int>> adj(n);\n        /// reversing the edge \n        for (auto& edge : edges) {\n            adj[edge[1]].push_back(edge[0]);\n        }\n        std::vector<std::vector<int>> ancestors(n);\n        for (int i = 0; i < n; i++) {\n            std::vector<bool> visited(n, false);\n            bfs(i, adj, ancestors[i], visited);\n            sort(ancestors[i].begin(), ancestors[i].end());\n        }\n        return ancestors;\n    }\n};\n```
['C++']