DSU | Easy C++ Solution
Code
# Code
```cpp []
class DisjointSet {
    private:
    vector < int > parent, rank;
    public:
    DisjointSet (int n) {
        parent.resize(n, 0);
        rank.resize(n, 0);
        for (int i = 0; i < n; i ++) {
            parent[i] = i;
        }
    }
    int findUp(int node) {
        if (parent[node] == node) {
            return node;
        }
        return parent[node] = findUp(parent[node]);
    }
    bool unionByRank(int a, int b) {
        int pa = findUp(a), pb = findUp(b);
        if (pa == pb) {
            return false;
        }
        if (rank[pa] > rank[pb]) {
            parent[pa] = pb;
        } else if (rank[pa] < rank[pb]) {
            parent[pb] = pa;
        } else {
            parent[pa] = pb;
            rank[pa] ++;
        }
        return true;
    }
};
class Solution {
public:
    int numberOfComponents(vector<vector<int>>& a, int k) {
        int n = a.size(), m = a[0].size(), ans = n;
        vector < vector < int > > dp (n, vector < int > (101, 0));
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < m; j ++) {
                dp[i][a[i][j]]++;
            }
        }
        DisjointSet ds(n);
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                int count = 0;
                for (int k = 1; k <= 100; k ++) {
                    if(dp[i][k] && dp[j][k]) {
                        count++;
                    }
                }
                if (count >= k) {
                    if (ds.unionByRank(i, j)) {
                        ans --;
                    }
                }
            }
        }
        return ans;
    }
};
```
['Array', 'Union Find', 'Graph', 'C++']