[C++] Basic DFS Solution | No erasing required | Mark direction of Edges
\nclass Solution {\npublic:\n    // Correct Solution\n    // We are just making an undirected graph, where we are giving (+ve) sign to outgoing\n    // edges an
```\nclass Solution {\npublic:\n    // Correct Solution\n    // We are just making an undirected graph, where we are giving (+ve) sign to outgoing\n    // edges and pretending that there is also the same incoming edge (or in general the opposite edge)\n    // and inserting it into the adj[] list as (-ve) elements.\n    // This is done so that the DFS doesn\'t stop when there are no outgoing edges \n    // (+ve edges) from the current edge. (Because there might be more outgoing edges afterwards)\n    // Without the above idea, the basic idea fails in this test case : [[1,2],[2,0]].\n    \n    // Link to not fully correct code is given below\n    // https://leetcode.com/submissions/detail/603533278/\n    // This approach gets 72/76 test cases correct, but is not logically correct.\n    // The below implementation corrects that.\n    void makeGraph(vector<vector<int>>& connections,vector<int> adj[]){\n        for(int i=0; i<connections.size(); i++){\n            adj[connections[i][0]].push_back(connections[i][1]);\n            adj[connections[i][1]].push_back(-connections[i][0]);\n        }\n    }\n    void dfs(vector<int> adj[],vector<bool>& visited,int src,int &ans){\n        visited[src] = true;\n        for(int &v : adj[src]){\n            if(!visited[abs(v)]){\n                if(v > 0)\n                    ans++;\n                dfs(adj,visited,abs(v),ans);\n            }\n        }\n    }\n    int minReorder(int n, vector<vector<int>>& connections) {\n        vector<int> adj[n];\n        vector<bool> visited(n,false);\n        int ans = 0;\n        makeGraph(connections,adj);\n        \n        dfs(adj,visited,0,ans);\n        return ans;\n    }\n};\n```
['Depth-First Search', 'C', 'C++']