Complete Explanation with intuition || Simple DFS || Easy to understand
\n\n\nclass Solution {\npublic:\n    void dfs(vector<vector<pair<int, int>>>&adj, vector<bool>& visited, int& ans, int currNode)\n    {\n        visited[currNod
![image](https://assets.leetcode.com/users/images/854694eb-e723-44cc-9129-b8176c865a17_1679619937.4753957.png)\n\n```\nclass Solution {\npublic:\n    void dfs(vector<vector<pair<int, int>>>&adj, vector<bool>& visited, int& ans, int currNode)\n    {\n        visited[currNode] = true;\n        for (pair<int, int>adjNode : adj[currNode])\n        {\n            //Curr = source, Next = adjNode.first\n            if (visited[adjNode.first]) continue;\n            \n            //adjNode.second == 1 means that there is a real edge from \'Curr\' to \'Next\'\n            bool isEdgeOutward = (adjNode.second == 1); \n            if (isEdgeOutward) ans++; //but we want edge to come from \'Next\' to \'Curr\', so change direction \n            dfs(adj, visited, ans, adjNode.first);\n        }\n    }\n    int minReorder(int n, vector<vector<int>>& connections) \n    {\n        vector<vector<pair<int, int>>>adj(n);\n        for(vector<int>connection : connections)\n        {\n            adj[connection[0]].push_back({connection[1], 1}); //real edge \n            adj[connection[1]].push_back({connection[0], -1}); //false edge made for traversal\n        }\n        //===========================================================\n        vector<bool>visited(n, false);\n        int ans = 0;\n        dfs(adj, visited, ans, 0);\n        return ans;\n    }\n};\n```
['Depth-First Search', 'Graph', 'C', 'C++']