C++ Easy BFS Solution
\nclass Solution {\npublic:\n    \n    void bfs(vector<vector<int>> &adj_list, vector<vector<bool>> &visited, int v)\n    {\n        queue<int> q;\n        q.pu
```\nclass Solution {\npublic:\n    \n    void bfs(vector<vector<int>> &adj_list, vector<vector<bool>> &visited, int v)\n    {\n        queue<int> q;\n        q.push(v);\n        \n        while(!q.empty()){\n            auto temp = q.front();\n            q.pop();\n            \n            for(auto j : adj_list[temp]){\n                if(visited[v][j] == false){\n                    visited[v][j] = true;\n                    q.push(j);\n                }\n            }\n        }\n    }\n    \n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> adj_list(n);\n        \n        for(int i=0;i<edges.size();i++){\n            adj_list[edges[i][0]].push_back(edges[i][1]);\n        }\n        \n        vector<vector<bool>> visited(n,vector<bool>(n,false));\n        \n        for(int i=0;i<n;i++){\n            bfs(adj_list, visited, i);\n        }\n        \n        vector<vector<int>> ans(n);\n        \n        for(int i=0;i<visited.size();i++){\n            for(int j=0;j<visited[i].size();j++){\n                if(visited[i][j] == true){\n                    ans[j].push_back(i);\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['Breadth-First Search']