Snippets Collections
class UnionFind 
{
    public: 
    vector<int> parent,count;
    UnionFind(int n){
        parent.resize(n, -1);
        count.resize(n, 1);
    }
    int find(int x){
        return (this->parent[x] == -1)? x : find(this->parent[x]);
    }
    void Union(int a, int b){
        int pA = find(a) , pB = find(b);
        if(pA != pB){
            this->parent[pB] = pA;
            this->count[pA] += this->count[pB];
        }
        
    }
};
star

Fri Jun 02 2023 06:16:54 GMT+0000 (Coordinated Universal Time) https://leetcode.com/problems/detonate-the-maximum-bombs/

#c++ #union-find-class

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension