We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 20fee0d commit 3fb8535Copy full SHA for 3fb8535
1 file changed
โing-eoking/๋คํธ์ํฌ.pyโ
@@ -0,0 +1,8 @@
1
+def solution(n, computers):
2
+ root = list(range(n))
3
+ find = lambda x: x if x == root[x] else find(root[x])
4
+ for i in range(n):
5
+ for j in range(n):
6
+ if computers[i][j] == 0 or i == j: continue
7
+ if (a := find(i)) != (b := find(j)): root[b] = a
8
+ return len(set(find(i) for i in range(n)))
0 commit comments