Skip to content

Commit 0895aae

Browse files
authored
🐜 Study: μ „λ ₯망을 λ‘˜λ‘œ λ‚˜λˆ„κΈ° (#78)
1 parent c3b3d89 commit 0895aae

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def solution(n, wires):
2+
answer = []
3+
find = lambda x: x if x == root[x] else find(root[x])
4+
for i in range(len(wires)):
5+
nw = wires[:i] + wires[i+1:]
6+
root = list(range(n))
7+
for a, b in nw:
8+
if (x := find(a - 1)) != (y := find(b - 1)): root[y] = x
9+
answer.append([find(i) for i in root].count(find(root[0])))
10+
return min([abs(n - 2 * x) for x in answer])

0 commit comments

Comments
Β (0)