Java beats 96% just a few lines
\n public int minReorder(int n, int[][] connections) {\n        int res = 0;\n        Set<Integer> s = new HashSet<>();\n        int u, v;\n        s.add(0);\n 
```\n public int minReorder(int n, int[][] connections) {\n        int res = 0;\n        Set<Integer> s = new HashSet<>();\n        int u, v;\n        s.add(0);\n        \n        while (s.size() != n) {\n            for (int i = 0; i < connections.length; i++) {\n                u = connections[i][0];\n                v = connections[i][1];\n                \n                if (s.contains(u) && !s.contains(v)) {\n                    s.add(v);\n                    res += 1;\n                } else if (s.contains(v) && !s.contains(u)) {\n                    s.add(u);\n                }\n            }\n        }\n        \n        return res;\n    }\n```
[]