Similar to topological sort function (dfs)
| 2 | |
| 3 | // Similar to topological sort function (dfs) |
| 4 | void dfs(int node,vector<int> adj[],vector<bool> &visited,stack<int> &stk) |
| 5 | { |
| 6 | visited[node] = true; |
| 7 | |
| 8 | for(auto child: adj[node]) |
| 9 | { |
| 10 | if(!visited[child]) |
| 11 | { |
| 12 | dfs(child,adj,visited,stk); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | stk.push(node); |
| 17 | } |
| 18 | |
| 19 | void dfsRec(int node,vector<int> g[],vector<bool> &visited) |
| 20 | { |