🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
```java package test; import ds.UF; import ds.impl.DefaultUF; import ds.impl.QuickFindUF; import ds.impl.QuickUnionUF; public class UFTest { public static void main(String[] args) { UF uf; int findResult; uf = new QuickFindUF(10); uf.union(4, 3); uf.union(3, 8); uf.union(6, 5); uf.union(9, 4); uf.union(2, 1); uf.union(5, 0); uf.union(7, 2); uf.union(6, 1); findResult = uf.find(3); System.out.println(findResult); System.out.println(uf.size()); System.out.println(uf.connected(4, 3)); System.out.println(uf.connected(9, 3)); uf = new DefaultUF(10); uf.union(4, 3); uf.union(3, 8); uf.union(6, 5); uf.union(9, 4); uf.union(2, 1); uf.union(5, 0); uf.union(7, 2); uf.union(6, 1); findResult = uf.find(3); System.out.println(findResult); System.out.println(uf.size()); System.out.println(uf.connected(4, 3)); System.out.println(uf.connected(9, 3)); uf = new QuickUnionUF(10); uf.union(4, 3); uf.union(3, 8); uf.union(6, 5); uf.union(9, 4); uf.union(2, 1); uf.union(5, 0); uf.union(7, 2); uf.union(6, 1); findResult = uf.find(3); System.out.println(findResult); System.out.println(uf.size()); System.out.println(uf.connected(4, 3)); System.out.println(uf.connected(9, 3)); } } ```