Skip to content

Commit 3fb8535

Browse files
ing-eokingbugs-bot
authored andcommitted
๐Ÿœ Study: ๋„คํŠธ์›Œํฌ (#51)
1 parent 20fee0d commit 3fb8535

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
ย (0)