We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c3b3d89 commit 0895aaeCopy full SHA for 0895aae
βμ λ ₯λ§μ λλ‘ λλκΈ°.pyβ
@@ -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