Simple BFS Solution
Idea?\n Consider every node as the source point and start breadth first search from that node.\n Whatever, the node that will be visited during the path have th
**Idea?**\n* Consider every node as the source point and start breadth first search from that node.\n* Whatever, the node that will be visited during the path have the ancestors as source node.\n\n```\nclass Solution {\npublic:\n    // Time Complexity:- O(N^2)\n    // Space Complexity:- O(N^2)\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<int> adj[n];\n        vector<vector<int>> ans(n);\n        for(auto& edge:edges){\n            adj[edge[0]].push_back(edge[1]);\n        }\n        \n        for(int i=0;i<n;i++){\n            vector<bool> vis(n);\n            queue<int> q;\n            \n            q.push(i);\n            vis[i] = true;\n            \n            while(!q.empty()){\n                int v = q.front();\n                q.pop();\n                \n                for(auto& u:adj[v]){\n                    if(!vis[u]){\n                        q.push(u);\n                        vis[u] = true;\n                        ans[u].push_back(i);\n                    }\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n```
[]