✅ Java | Easy | BFS
\nclass Solution {\n    public int minReorder(int n, int[][] connections) {\n        List<List<Integer>> adj=new ArrayList<>();\n        for(int i=0;i<n;i++){\n
```\nclass Solution {\n    public int minReorder(int n, int[][] connections) {\n        List<List<Integer>> adj=new ArrayList<>();\n        for(int i=0;i<n;i++){\n            adj.add(new ArrayList<>());\n        }\n        for(int i=0;i<connections.length;i++){\n            adj.get(connections[i][0]).add(connections[i][1]);\n            adj.get(connections[i][1]).add(-connections[i][0]);\n        }\n        boolean vis[]=new boolean[n];\n        int cnt=0;\n        Queue<Integer> qu=new LinkedList<>();\n        qu.add(0);\n        vis[0]=true;\n        while(!qu.isEmpty()){\n            int curr=qu.poll();\n            for(int it:adj.get(Math.abs(curr))){\n                if(!vis[Math.abs(it)]){\n                    qu.add(it);\n                    vis[Math.abs(it)]=true;\n                    if(it>0)\n                        cnt++;\n                }\n            }\n        }\n        return cnt;\n    }\n}\n```\n![image](https://assets.leetcode.com/users/images/af6da766-cb39-4d74-aa65-280fcb12a95a_1679625092.5902467.jpeg)\n
['Breadth-First Search', 'Graph', 'Java']