Java NO BFS/DFS. Only use Set O(V*E), Beat 100% Time, 100% Space.
Use set to contains node, and remove the node which can connect to 0.\nthere are 3 situtions: since edge is  a -> b\n1. from 0 start edge, should reverse for su
Use set to contains node, and remove the node which can connect to 0.\nthere are 3 situtions: since edge is  a -> b\n1. from 0 start edge, should reverse for sure, count++;\n2. a - > b, if set NOT contains a, means a can connect to 0, and this edge a->b should reverse. count++;\n3. a -> b, if set NOT contains b, means b is connect to 0, and a is point to b, so nothing to do. continue scan.\n\n```\nclass Solution {\n    public int minReorder(int n, int[][] connections) {\n        HashSet<Integer> set = new HashSet<>();\n        for(int i = 0; i < n; i++) {\n            set.add(i);\n        }\n        set.remove(0);\n        int count = 0;\n        while(!set.isEmpty()) {\n            for(int[] connection: connections) {\n                // a -> b;\n                int a = connection[0];\n                int b = connection[1];\n                \n                // if a, b both don\'t contains, means we already checked before.\n                if(!set.contains(a) && !set.contains(b)) {\n                    continue;\n                }\n                \n                if(a == 0) {\n                    // if start from 0 to other city, this edge should reverse;\n                    count++;\n                    set.remove(b);\n                } else if(!set.contains(a)) {\n                    // if a is connect to 0, b is not, this edge should reverse;\n                    count++;\n                    set.remove(b);\n                } else if(!set.contains(b)) {\n                    // if b is connect to 0, and a -> b, nothing to do, continue;\n                    set.remove(a);\n                } \n            }\n        }\n        return count;\n    }\n}\n```
[]