전력망을 둘로 나누기
-
[Algorithm - 프로그래머스] Python 전력망을 둘로 나누기Programming/Algorithm 2021. 11. 23. 21:06
문제 (LV.2) https://programmers.co.kr/learn/courses/30/lessons/86971 코드 answer = 0 def bfs(wires, checked, num, cnt): global answer q = [num] while len(q) != 0: cur = q.pop(0) for i in range(0, len(wires)): if wires[i][0] == cur: if checked[wires[i][1]] == 0: checked[wires[i][1]] = 1 q.append(wires[i][1]) cnt += 1 elif wires[i][1] == cur: if checked[wires[i][0]] == 0: checked[wires[i][0]] = 1 q.ap..