Java easy with bfs
Approach\ncreate a map {city : neighbours} and set of all the edges\n\nnow do a bfs and check on every city if there is an edge (neigh, city) in our edge set, i
# Approach\ncreate a map {city : neighbours} and set of all the edges\n\nnow do a bfs and check on every city if there is an edge (neigh, city) in our edge set, if its not their increase the changes count. and move on to next city. keep visited set to avoid checking the already checked node.\n\n# Code\n```\nclass Solution {\n    public int minReorder(int n, int[][] connections) {\n\n        HashMap<Integer,List<Integer>> adjc = new HashMap<>();\n        HashSet<List<Integer>> edges = new HashSet<>();\n        HashSet<Integer> visited = new HashSet();\n\n        Queue<Integer> q = new LinkedList<>();\n        int changes =0;\n\n\n        for( int[] a : connections)\n        {\n            List<Integer> edge = new ArrayList();\n            edge.add(a[0]);\n            edge.add(a[1]);\n            edges.add(edge);\n            System.out.println(edge);\n\n            List<Integer> l1 = adjc.getOrDefault(a[0],new ArrayList());\n            List<Integer> l2 = adjc.getOrDefault(a[1],new ArrayList());\n\n            l1.add(a[1]);\n            l2.add(a[0]);\n            adjc.put(a[0],l1);\n            adjc.put(a[1],l2);\n        }\n\n        q.add(0);\n\n        while(!q.isEmpty())\n        {\n            int node = q.poll();\n            visited.add(node);\n\n            for(Integer neigh : adjc.get(node))\n            {\n                if(!visited.contains(neigh))\n                {\n                    q.add(neigh);\n                    List<Integer> nedge = new ArrayList();\n                    nedge.add(neigh);\n                    nedge.add(node);\n                    \n                    if(!edges.contains(nedge)) changes++;\n                    \n                }\n            }\n        }\n        return changes;\n    }\n}\n```
['Java']