Beats 93%🔥|| DFS🔥|| easy JAVA Solution✅
Code\n\nclass Solution {\n    class Pair{\n        int val;\n        boolean f;\n        Pair(int val,boolean f){\n            this.val=val;\n            this.f
# Code\n```\nclass Solution {\n    class Pair{\n        int val;\n        boolean f;\n        Pair(int val,boolean f){\n            this.val=val;\n            this.f=f;\n        }\n    }\n    int ans;\n    public int minReorder(int n, int[][] mat) {\n        List<List<Pair>> adj=new ArrayList<>();\n        for(int i=0;i<n;i++) adj.add(new ArrayList<>());\n        for(int[] arr:mat){\n            adj.get(arr[0]).add(new Pair(arr[1],true));\n            adj.get(arr[1]).add(new Pair(arr[0],false));\n        }\n        boolean[] vis=new boolean[n];\n        ans=0;\n        sol(adj,vis,0);\n        return ans;\n    }\n    public void sol(List<List<Pair>> adj,boolean[] vis,int idx){\n        vis[idx]=true;\n        for(Pair x:adj.get(idx)){\n            if(!vis[x.val]){\n                if(x.f) ans++;\n                sol(adj,vis,x.val);\n            }\n        }\n    }\n}\n```
['Depth-First Search', 'Java']