| 8 | */ |
| 9 | class Solution { |
| 10 | public static class Dus { |
| 11 | int[] parent; |
| 12 | int n; |
| 13 | |
| 14 | Dus(int n) { |
| 15 | this.n = n; |
| 16 | parent = new int[n]; |
| 17 | for (int i = 1; i < n; i++) { |
| 18 | parent[i] = i; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | public int find(int u) { |
| 23 | if (u != parent[u]) { |
| 24 | parent[u] = find(parent[u]); |
| 25 | } |
| 26 | return parent[u]; |
| 27 | } |
| 28 | |
| 29 | public void union(int u, int v) { |
| 30 | int pu = find(u); |
| 31 | int pv = find(v); |
| 32 | |
| 33 | if (pu != pv) { |
| 34 | parent[pv] = pu; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | public List<Boolean> areConnected(int n, int threshold, int[][] queries) { |
| 39 | ArrayList<Boolean> res = new ArrayList<>(); |
| 40 | Dus dus = new Dus(n+1); |
nothing calls this directly
no outgoing calls
no test coverage detected