DSU/UnionFind. 450ms
Code
# Code
```python3
class Solution:
    def numberOfComponents(self, grid: List[List[int]], k: int) -> int:
        def union(a,b):
            nonlocal components
            if (roota := find(a)) != (rootb := find(b)):
                if sizes[roota] > sizes[rootb]:
                    parents[rootb] = roota
                    sizes[roota] += sizes[rootb]
                else:
                    parents[roota] = rootb
                    sizes[rootb] += sizes[roota]
                components -= 1
        def find(e):
            if parents[e] != e:
                parents[e] = (e := find(parents[e]))
            return e
        
        components = N = len(grid)
        sizes = {i:1 for i in range(N)}
        parents = {i:i for i in range(N)}
        for i in range(N):
            for j in range(i + 1, N):
                if len(set(grid[i]) & set(grid[j])) >= k:
                    union(i, j)
        return components
```
['Union Find', 'Python3']