From a7d8329c16e441f831138a5399cf67afdce55c6b Mon Sep 17 00:00:00 2001 From: jsjseop <57559288+jsjseop@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:11:34 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Ayaan=20:=20=EB=AA=A8=EC=9D=8C=EC=82=AC?= =?UTF-8?q?=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...50\354\235\214\354\202\254\354\240\204.py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\353\252\250\354\235\214\354\202\254\354\240\204.py" diff --git "a/Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\353\252\250\354\235\214\354\202\254\354\240\204.py" "b/Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\353\252\250\354\235\214\354\202\254\354\240\204.py" new file mode 100644 index 0000000..48a0da6 --- /dev/null +++ "b/Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\353\252\250\354\235\214\354\202\254\354\240\204.py" @@ -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') From 1b110b58305cd42ba306431b524772598f126bce Mon Sep 17 00:00:00 2001 From: jsjseop <57559288+jsjseop@users.noreply.github.com> Date: Tue, 16 Jan 2024 14:09:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Ayaan=20:=20=EC=A0=84=EB=A0=A5=EB=A7=9D?= =?UTF-8?q?=EC=9D=84=20=EB=91=98=EB=A1=9C=20=EB=82=98=EB=88=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\202\230\353\210\204\352\270\260.py" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\354\240\204\353\240\245\353\247\235\354\235\204\353\221\230\353\241\234\353\202\230\353\210\204\352\270\260.py" diff --git "a/Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\354\240\204\353\240\245\353\247\235\354\235\204\353\221\230\353\241\234\353\202\230\353\210\204\352\270\260.py" "b/Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\354\240\204\353\240\245\353\247\235\354\235\204\353\221\230\353\241\234\353\202\230\353\210\204\352\270\260.py" new file mode 100644 index 0000000..32ad0a5 --- /dev/null +++ "b/Ayaan/programmers/\354\231\204\354\240\204\355\203\220\354\203\211/\354\240\204\353\240\245\353\247\235\354\235\204\353\221\230\353\241\234\353\202\230\353\210\204\352\270\260.py" @@ -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]])