Ancestors | Easy DFS
\nclass Solution {\npublic:\n    void dfs(vector<int> adj[],int s,vector<bool>& viz){\n        viz[s]=true;\n        for(auto x:adj[s]){\n            if(!viz[x]
```\nclass Solution {\npublic:\n    void dfs(vector<int> adj[],int s,vector<bool>& viz){\n        viz[s]=true;\n        for(auto x:adj[s]){\n            if(!viz[x]){\n                dfs(adj,x,viz);\n            }\n        }\n    }\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<int> adj[n];\n        for(int i=0;i<edges.size();i++){\n            int u=edges[i][0];\n            int v=edges[i][1];\n            adj[u].push_back(v);\n        }\n        \n        vector<vector<int>> rez(n);\n        for(int i=0;i<n;i++){\n            vector<bool>viz(n,false);\n            dfs(adj,i,viz);\n            \n            for(int j=0;j<n;j++){\n                if(viz[j] && i!=j){\n                    rez[j].push_back(i);\n                }\n            }\n        }\n        return rez;\n    }\n};\n```
['Depth-First Search', 'C', 'C++']