C ++ || Brute Force || DFS
The core idea is just reverse the edges in the graph and then simply do dfs from every node and check how many  nodes that current node visits.\n\nclass Solutio
The core idea is just reverse the edges in the graph and then simply do dfs from every node and check how many  nodes that current node visits.\n```\nclass Solution {\npublic:\n    void dfs(unordered_map<int,vector<int>> &gr,vector<bool> &vis,int src){\n        vis[src] = true;\n        \n        for(auto v:gr[src]){\n            if(!vis[v]){\n                dfs(gr,vis,v);\n            }\n        }\n    }\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        unordered_map<int,vector<int>>mp;\n        \n        for(auto i:edges){\n            mp[i[1]].push_back(i[0]);\n        }\n        \n        vector<vector<int>>ans;\n        \n        for(int i=0;i<n;i++){\n            \n            vector<bool>vis(n,false);\n            vector<int>tmp;\n            \n            dfs(mp,vis,i);\n            for(int j=0;j<n;j++){\n                if(vis[j] && i!=j){\n                    tmp.push_back(j);\n                }\n            }\n            \n            ans.push_back(tmp);\n        }\n        return ans;\n    }\n};\n```
['Depth-First Search', 'C']