C++ ✅ || BFS || Easy to Understand🔥
\n# Approach\n Describe your approach to solving the problem. \n\n\n Create an adjacency list to represent the connections between the cities. \n We initialise 
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n* Create an adjacency list to represent the connections between the cities. \n* We initialise the given directed edge with `weight 1` and create an opposite edge corresponding to the same with `weight 0`.\n\n* Initialize a queue to perform BFS, a vector to keep track of visited cities, and a variable to store the answer.\n\n* Add the city 0 to the queue with a weight of 0 since we don\'t need to reverse any roads to reach city 0 from itself.\n\n* While `q.empty()!=0`, take the front element of the queue and mark it as visited. Also, add the weight of the current element to the answer.\n\n* For each neighbor of the current city, if it has not been visited yet, add it to the queue with the corresponding weight. If it has already been visited, skip it.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n\n    int minReorder(int n, vector<vector<int>>& connections) {\n        \n        vector<vector<pair<int,int>>>adj(n);\n        for(auto it: connections){\n             adj[it[0]].push_back({it[1],1});\n             adj[it[1]].push_back({it[0],0});\n        }\n\n        queue<pair<int,int>>q;\n        vector<int>vis(n,-1);\n        q.push({0,0});\n        int ans=0;\n\n        while(!q.empty()){\n            int node=q.front().first;\n            int wt=q.front().second;\n            q.pop();\n            vis[node]=1;\n           \n            ans+=wt;\n\n            for(auto it: adj[node]){\n                if(vis[it.first]==-1) q.push(it);\n                else continue;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']