Skip to content

Commit

Permalink
Merge pull request #173 from codesquad-backend-study/ayaan
Browse files Browse the repository at this point in the history
Ayaan : 1월 셋째 주
  • Loading branch information
github-actions[bot] authored Jan 21, 2024
2 parents 28dbed6 + 1b110b5 commit 6c61821
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Ayaan/programmers/완전탐색/모음사전.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def solution(word):
alphabets = ['A', 'E', 'I', 'O', 'U']
answer = []
order = 0

def dfs(target):
nonlocal order
if target == word:
answer.append(order)
if len(target) == 5:
return

for alphabet in alphabets:
order += 1
dfs(target + alphabet)

dfs('')
return answer[0]


solution('I')
38 changes: 38 additions & 0 deletions Ayaan/programmers/완전탐색/전력망을둘로나누기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import collections


def bfs(graph, start, visited):
q = collections.deque([start])
visited[start] = True
cnt = 1

while q:
v = q.popleft()
for n in graph[v]:
if not visited[n]:
q.append(n)
visited[n] = True
cnt += 1
return cnt


def solution(n, wires):
answer = n
for i in range(len(wires)):
temp = wires[:]
graph = collections.defaultdict(list)
# i번째 연결을 뺀 graph를 만든다.
for idx, node in enumerate(temp):
if i == idx:
continue
graph[node[0]].append(node[1])
graph[node[1]].append(node[0])
# 한쪽의 개수를 구해서 차이를 계산한다.
cnt = bfs(graph, 1, [False] * (n + 1))
other = n - cnt
answer = min(answer, abs(cnt - other))

return answer


solution(4, [[1, 2], [2, 3], [3, 4]])

0 comments on commit 6c61821

Please sign in to comment.