🔥 Java ||  Simple BFS Solution with Explanation ✅
\uD83D\uDCCC\uD83D\uDCCC The idea is simple : Perform Breadth First Traversal from the starting vertex , move BREADTH-WISE and keep on counting the edges needs 
\uD83D\uDCCC\uD83D\uDCCC **The idea is simple** : *Perform Breadth First Traversal from the starting vertex , move BREADTH-WISE and keep on counting the edges needs to be reversed.  Outdegree Edges will be reversed while Indegree edges will be not*\uD83D\uDC4D\uD83C\uDFFB\n\nNow Lets say in BFS Traversal we reached some vertex **3** and from this we can reach to **0**.\nYou have 2 types of edges on vertex **3**, either going outwards \uD83D\uDC49\uD83C\uDFFB( outdegree  ) or inwards \uD83D\uDC48\uD83C\uDFFB( indegree ).\n\nCase 1\uFE0F\u20E3 : Now since, you can already reach \'0\' from \'3\' so you can also reach \'0\' from indegree vertices of \'3\' (i.e. vertices from which an edge comes to \'3\'). So you dont need to reverse any edge . Just simply add indegree neighbours to the queue for further BFS exploration.\n\nCase 2\uFE0F\u20E3 : The edges which are outdegree of \'3\' , you need to reverse them all. So for every outdegree vertex ( i.e. vertices to which \'3\' has an edge going to it)  , add 1 (one) to your count variable and add the neighbour to the queue for furthur exploration.\n\nAfter processing any vertex mark it visited \u2705\n\n\uD83D\uDED1 Point to Note --> In Case 01 , where you are adding all the indegree vertices of the current vertex to the queue, you need to also need to remove those indegree ( incoming ) edges otherwise the current vertex will become as outdegree of the neighbour and it will be counted in the answer even when it is already processed.\n\nFor Example : Lets say the graph is like this \n                        0--> 1 --> 10 <--4\n\t\t\t\t\t\tand you are currenlty at vertex 10 in BFS ( means 10 can reach 0 )\n\t\t\t\t\t\tYou know that 10 has one indegree vertex \'4\' so you will \n\t\t\t\t\t\tadd \'4\' to the queue ( no need to reverse this edge ).  But Before adding \'4\' to the queue you also remove the indegree edge coming to \'10\' from \'4\' otherwise in future when we will be processing \'4\' we will see the outdegree edge going towards \'10\' and we will increase the count by 1 which was not even required \u203C\uFE0F. \n\n\n```\nclass Solution {\n    \n    public int minReorder(int n, int[][] connections) {\n        \n        HashSet<Integer>[] outdegree = new HashSet[n];  //outdegree of every vertex\n        HashSet<Integer>[] indegree = new HashSet[n];  //indegree of every vertex\n        for(int i=0;i<n;i++){\n             outdegree[i] = new HashSet<>();\n             indegree [i] = new HashSet<>();\n        }\n        \n        int l = connections.length;\n        for(int i=0;i<l;i++)\n        {\n            int x = connections[i][0];\n            int y = connections[i][1];\n            \n            outdegree[x].add(y);\n            indegree[y].add(x);\n        }\n        \n        int[] vis = new int[n];   // visited array to store already processed vertices\n        Queue<Integer> queue = new LinkedList<>();\n        queue.add(0);\n        \n        int ans = 0;\n        while(!queue.isEmpty())\n        {\n            int vtx = queue.remove();\n            if(vis[vtx]==1) continue;\n\t\t\t\n\t\t\t//for every outdegree neighbour of current vertex\n            for(Integer nbr : outdegree[vtx])  \n            {\n                ans+=1;\n                queue.add(nbr);\n            }\n            \n\t\t\t// for every in-degree neighbour , add to the queue and remove that indegree edge \n            for(Integer nbr : indegree[vtx])  \n            {                                      \n                outdegree[nbr].remove(vtx);\n                queue.add(nbr);\n            }\n\t\t\t\n\t\t\t// and finally mark this vertex as visited/processed\n            vis[vtx]=1;     \n        }\n        \n        return ans;   \n    }\n}\n```\n\n\uD83D\uDCCC Upvote If you Liked The Approach \uD83D\uDE04\uD83D\uDE0A
['Breadth-First Search']