JAVA | Easy Solution Using Adjacency List
\nclass Solution {\n    List<Integer>[] incoming, outgoing;\n    HashSet<Integer> visited;\n    int ans;\n    public int minReorder(int n, int[][] connections){
```\nclass Solution {\n    List<Integer>[] incoming, outgoing;\n    HashSet<Integer> visited;\n    int ans;\n    public int minReorder(int n, int[][] connections){\n        ans = 0;\n        incoming = new ArrayList[n];\n        outgoing = new ArrayList[n];\n        for(int i = 0; i < n; i++){\n            incoming[i] = new ArrayList();\n            outgoing[i] = new ArrayList();\n        }\n        for(int edge[] : connections){\n            incoming[edge[1]].add(edge[0]);\n            outgoing[edge[0]].add(edge[1]);\n        }\n        visited = new HashSet();\n        dfs(0);\n        return ans;\n    }\n    void dfs(int v){\n        visited.add(v);\n        for(int i : outgoing[v])\n            if(!visited.contains(i)){\n                ans++;\n                dfs(i);\n            }\n        for(int i: incoming[v])\n            if(!visited.contains(i))\n                dfs(i);\n    }\n}\n```\n## DO UPVOTE IF YOU LIKE THE SOLUTION
['Depth-First Search', 'Graph', 'Java']