Using BFS C++ Easy Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minReorder(int n, vector<vector<int>>& connections) {\n        unordered_map<int,vector<pair<int,bool>>> mp;\n        for(auto it:connections)\n        {\n            mp[it[0]].push_back({it[1],1});\n            mp[it[1]].push_back({it[0],0});\n        }\n        vector<int> vis(n,0);\n        int ans=0;\n        for(int i=0;i<n;i++)\n        {\n            if(!vis[i])\n            {\n                queue<int> q;\n                q.push(i);\n                vis[i]=1;\n                while(!q.empty())\n                {\n                    int node=q.front();\n                    q.pop();\n                    vis[node]=1;\n                    for(auto it:mp[node])\n                    {\n                        if(!vis[it.first])\n                        {\n                            if(it.second==1)\n                            {\n                               ans++;\n                            }\n                            q.push(it.first);\n                            vis[it.first]=1;\n                        }\n                    }\n                }\n\n            }\n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'C++']