Easy C++ Solution without Graphs
I am inserting those nodes into the set from which we are having a path to 0. say -\neg- n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]\nnow I add 0 to th
I am inserting those nodes into the set from which we are having a path to 0. say -\neg- n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]\nnow I add 0 to the set , now connection[0] represents a path from 0 to 1, but i want this from 1 to 0, so I increased the count by 1.\nNow this means I have reversed this path , therefore there is a path from 1 to 0 , so I insert 1 to the set,\nand so on...\nif there is already a path , so i am just inserting that node to the set without increasing the count.\n```\n\n    int minReorder(int n, vector<vector<int>>& connections) {\n        \n        int count =  0;\n        \n       unordered_set<int>st;\n       st.insert(0);\n        \n        for( int i = 0 ; i < connections.size() ; i++ ){\n            \n            if( st.find(connections[i][1]) == st.end() ){\n                st.insert(connections[i][1]);\n                    count++;\n            }\n            \n            else\n                st.insert( connections[i][0]);\n        }\n        \n        return count;\n    }\n```
[]