✅ C++ Solution || Set and Queue||
\nclass Solution {\npublic:\n    \n    \n    vector<int> getAll(int node , vector<int> adj[])\n    {\n        \n        vector<int> ans;\n        \n        set<
```\nclass Solution {\npublic:\n    \n    \n    vector<int> getAll(int node , vector<int> adj[])\n    {\n        \n        vector<int> ans;\n        \n        set<int> s;\n        queue<int> q;\n        q.push(node);\n        \n        while(!q.empty())\n        {\n            int x=q.front();\n            q.pop();\n            \n            for(auto &it:adj[x])\n            {\n                if(s.find(it)==s.end())\n                {\n                    s.insert(it);\n                    q.push(it);\n                }\n            }\n        }\n        \n        for(auto &it:s)\n            ans.push_back(it);\n        return ans;\n    }\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        \n        \n       \n         vector<int> adj[n];\n        for(int i=0;i<edges.size();i++)\n        {\n            int from=edges[i][0];\n            int to=edges[i][1];\n            \n            adj[to].push_back(from);  // transpose\n            \n        }\n        \n        vector<vector<int>> ans;\n        \n        for(int i=0;i<n;i++)\n        {\n            vector<int> temp=getAll(i,adj);\n            \n            ans.push_back(temp);\n        }\n        \n\n        return ans;\n        \n    }\n};\n```
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'C', 'C++']