Algorithm – Union Find

public class UnionFind {

static class QuickFindUF {
// id[i] is
int[] id;

/**
* Initialize data structure
*/
QuickFindUF(int N) {
id = new int[N];
for (int i = 0; i < N; i++) { id[i] = i; } } /** * p and q are connected if they have the same id. Time complexity is O(1) */ public boolean connected(int p, int q) { return id[p] == id[q]; } /** * To merge components containing p and q, change all entries whose id equals

Algorithm – Union Find最先出现在Python成神之路

版权声明:
作者:感冒的梵高
链接:https://www.techfm.club/p/9997.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>