MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Dus

Class Dus

Java/graph_connectivity_with_threshold.java:10–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8*/
9class 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);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected