We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fc3f861 commit 154cbd9Copy full SHA for 154cbd9
1 file changed
live9/test95/문제2/백유진.py
@@ -0,0 +1,32 @@
1
+def dfs(node, graph, visited):
2
+ visited[node] = True
3
+ size = 1
4
+
5
+ for neighbor in graph[node]:
6
+ if not visited[neighbor]:
7
+ size += dfs(neighbor, graph, visited)
8
9
+ return size
10
11
+def solution(n, wires):
12
+ answer = float('inf')
13
14
+ for i in range(len(wires)):
15
+ count = 0
16
+ w_copy = wires[:]
17
+ w_copy.pop(i)
18
+ print(w_copy)
19
+ graph = [[] for _ in range(n+1)]
20
21
+ for wire in w_copy:
22
+ graph[wire[0]].append(wire[1])
23
+ graph[wire[1]].append(wire[0])
24
25
+ visited = [False] * (n + 1)
26
+ size_one = dfs(w_copy[0][0], graph, visited)
27
+ size_two = n - size_one
28
29
+ answer = min(answer, abs(size_one - size_two))
30
31
+ print(count)
32
+ return answer
0 commit comments