Easy to Understand simple Bfs beats 100% O(n)
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:\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minReorder(int n, vector<vector<int>>& connections) {\n        unordered_set<int> passingcities;\n        unordered_map<int, vector<int>> graph;\n        for(int i = 0; i < connections.size(); i++) {\n            graph[connections[i][0]].push_back(connections[i][1]);\n        }\n\n        unordered_map<int, vector<int>> cities_passed;\n        for(int i = 0; i < connections.size(); i++) {\n            cities_passed[connections[i][1]].push_back(connections[i][0]);\n        }\n\n        queue<int> q;\n        q.push(0);\n        while(!q.empty()) {\n            int temp = q.front();\n            q.pop();\n            passingcities.insert(temp);\n            int i = 0;\n            while(i < cities_passed[temp].size()) {\n                if(passingcities.find(cities_passed[temp][i]) == passingcities.end()) {\n                    q.push(cities_passed[temp][i]);\n                }\n                i++;\n            }\n        }\n        if(passingcities.size() == n) return 0;\n\n        queue<int> map;\n        for(int num : passingcities) {\n            map.push(num);\n        }\n        int count = 0;\n        while(!map.empty()) {\n            int temp = map.front();\n            map.pop();\n            int i = 0;\n            for(int num : cities_passed[temp]) {\n                if(passingcities.find(num) == passingcities.end()) {\n                    passingcities.insert(num);\n                    cout << "added " << num << " due to  " << temp << endl;\n                    map.push(num);\n                }\n            }\n            while(i < graph[temp].size()) {\n                if(passingcities.find(graph[temp][i]) == passingcities.end()) {\n                    passingcities.insert(graph[temp][i]);\n                    count++;\n                    cout << "edge changed for " << temp << "  " << graph[temp][i] << endl;\n                    map.push(graph[temp][i]);\n                    cout << "passing cities " << graph[temp][i] << endl;\n                }\n                i++;\n            }\n        }\n        return count;\n    }\n};\n```
['C++']