[java] two union find for Alice and Bob
\nclass Solution {\n    public int maxNumEdgesToRemove(int n, int[][] edges) {\n        UF a = new UF(n + 1);\n        UF b = new UF(n + 1);\n        int extra 
```\nclass Solution {\n    public int maxNumEdgesToRemove(int n, int[][] edges) {\n        UF a = new UF(n + 1);\n        UF b = new UF(n + 1);\n        int extra = 0;\n        for (int[] e: edges) {\n            if (e[0] != 3) continue;\n            boolean ext = false;\n            if (!a.add(e)) ext = true;\n            if (!b.add(e)) ext = true;\n            if (ext) extra++;\n        }\n        for (int[] e: edges) {\n            if (e[0] == 1 && !a.add(e)) extra++;\n            if (e[0] == 2 && !b.add(e)) extra++;\n        }\n        return a.isConnected() && b.isConnected() ? extra : -1;\n    }\n}\n\nclass UF {\n    int[] nodes;\n    int edjCnt = 0;\n    UF(int n) {\n        nodes = new int[n];\n        for(int i = 0; i < n; i++)\n            nodes[i] = i;\n    }\n    \n    boolean isConnected() {\n        return (nodes.length - 1 - 1) == edjCnt;\n    }\n    \n    boolean add(int[] edj) {\n        int aHead = head(edj[1]);\n        int bHead = head(edj[2]);\n        if (aHead != bHead) {\n            nodes[bHead] = aHead;\n            edjCnt++;\n            return true;\n        }\n        return false;\n    }\n    \n    int head(int n) {\n        if (n != nodes[n]) \n            nodes[n] = head(nodes[n]);\n        return nodes[n];\n    }\n}\n```
['Union Find', 'Java']