C++ Solution
Approach\n Describe your approach to solving the problem. \n    DFS\n\n# Code\n\nclass Solution {\npublic:\n    vector<pair<int, int>> g[50005];\n    int ans, v
# Approach\n<!-- Describe your approach to solving the problem. -->\n    DFS\n\n# Code\n```\nclass Solution {\npublic:\n    vector<pair<int, int>> g[50005];\n    int ans, vis[50005];\n    void dfs(int u) {\n        vis[u] = 1;\n        for(auto v: g[u]) {\n            if(!vis[v.first]) {\n                ans += v.second;\n                dfs(v.first);\n            }\n        }\n    }\n    int minReorder(int n, vector<vector<int>>& connections) {\n        for(auto x: connections) {\n            g[x[0]].push_back({x[1], 1});\n            g[x[1]].push_back({x[0], 0});\n        }\n        ans = 0;\n        dfs(0);\n        return ans;\n    }\n};\n```
['C++']