JAVA || Easy Solution with Explanation || 100% Faster code
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\nPLEASE UPVOTE IF YOU LIKE..\n```\nclass Solution {\n    public int minReorder(int n, int[][] connections) {\n        List<List<Edge>> graph = new ArrayList<>();\n        for(int i = 0; i < n; i++) {\n            graph.add(new ArrayList<>());\n        }\n        \n        for(int i = 0; i < connections.length; i++) {\n            // 1 denotes original edge\n            graph.get(connections[i][0]).add(new Edge(connections[i][1], 1));\n            \n            // 0 denotes reversed edge\n            graph.get(connections[i][1]).add(new Edge(connections[i][0], 0));\n        }\n        \n        // Run a dfs from 0 and dissolve(mark) the edges that can be reached from zero, thereby increasing the count\n        // Because if an edge is directly reachable from 0, it actually needs to get reversed\n        return dfs(graph, 0, new boolean[n]);\n    }\n    \n    // DFS\n    private int dfs(List<List<Edge>> graph, int source, boolean[] isVisited) {\n        int cost = 0;\n        isVisited[source] = true;\n        \n        for(Edge neighbour : graph.get(source)) {\n            if(!isVisited[neighbour.vertex]) {\n                cost += neighbour.count + dfs(graph, neighbour.vertex, isVisited);\n            }\n        }\n        return cost;\n    }\n    \n    private class Edge {\n        int vertex, count;\n        public Edge(int vertex, int count) {\n            this.vertex = vertex;\n            this.count = count;\n        }\n    }\n}\n```
['Java']