From e189ed444128309c7835a85c9b1defb53b6e442e Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Tue, 14 May 2024 01:43:44 +0900 Subject: [PATCH 1/3] 2024-05-14 --- tgyuuAn/README.md | 19 +++--- ...0 \353\217\204\354\260\251\354\247\200.py" | 58 +++++++++++++++++++ 2 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 "tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index cbc8e16b..5f86a575 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -45,14 +45,15 @@ | 41차시 | 2024.03.04 | DP | 자두나무 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148 | 42차시 | 2024.03.07 | DFS | 스도쿠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152 | 43차시 | 2024.03.10 | 이분 탐색 | 징검다리 건너기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/157 -| 44차시 | 2023.03.13 | 트라이 | 개미굴 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159 -| 45차시 | 2023.03.16 | 트라이 | 트라이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162 -| 46차시 | 2023.03.20 | 트라이 | AB | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/165 -| 47차시 | 2023.03.22 | 수학, 분할정복 | 너 봄에는 캡사이신이 맛있단다 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/167 -| 48차시 | 2023.03.25 | 벨만 포드 | 골목길 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/171 -| 49차시 | 2023.03.29 | DP | KCM Travel | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/174 +| 44차시 | 2024.03.13 | 트라이 | 개미굴 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159 +| 45차시 | 2024.03.16 | 트라이 | 트라이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162 +| 46차시 | 2024.03.20 | 트라이 | AB | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/165 +| 47차시 | 2024.03.22 | 수학, 분할정복 | 너 봄에는 캡사이신이 맛있단다 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/167 +| 48차시 | 2024.03.25 | 벨만 포드 | 골목길 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/171 +| 49차시 | 2024.03.29 | DP | KCM Travel | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/174 | 50차시 | 2024.04.01 | BFS | 열쇠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/175 -| 51차시 | 2023.04.07 | BFS | 과외맨 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/179 -| 52차시 | 2023.05.06 | 위상정렬 | 게임 개발 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/182 -| 53차시 | 2023.05.09 | 백트래킹 | 2048 (Easy) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184 +| 51차시 | 2024.04.07 | BFS | 과외맨 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/179 +| 52차시 | 2024.05.06 | 위상정렬 | 게임 개발 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/182 +| 53차시 | 2024.05.09 | 백트래킹 | 2048 (Easy) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184 +| 54차시 | 2024.05.14 | 다익스트라 | 미확인 도착지 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/185 --- diff --git "a/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.py" "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.py" new file mode 100644 index 00000000..2fd5f947 --- /dev/null +++ "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.py" @@ -0,0 +1,58 @@ +from collections import defaultdict +from heapq import * +import sys + +INF = 50_000_001 + +def input(): return sys.stdin.readline().rstrip() + +T = int(input()) + +for _ in range(T): + cnt_node, cnt_edge, cnt_dedication = map(int, input().split()) + start_node, g, h = map(int, input().split()) + + graph = defaultdict(lambda : defaultdict(int)) + for _ in range(cnt_edge): + start, destination, cost = map(int,input().split()) + graph[start][destination] = cost + graph[destination][start] = cost + + node_dedications = set() + for _ in range(cnt_dedication): + node_dedications.add(int(input())) + + table = [INF for _ in range(cnt_node+1)] + table[start_node] = 0 + + visited = set() + heap = [] + heappush(heap, [0, start_node, 1]) + flag = [1 for _ in range(cnt_node+1)] + + while heap: + now_cost, now_node, now_flag = heappop(heap) + + if now_node in visited: continue + visited.add(now_node) + + if flag[now_node] == 1 and now_flag == 0: flag[now_node] = 0 + + for next_node in graph[now_node]: + cost = graph[now_node][next_node] + + if (now_cost + cost) > table[next_node]: continue + + table[next_node] = now_cost + cost + + new_flag = now_flag + # 만약, 지금 움직이려는 도로가 냄새가 나는 도로였을 경우 flag를 0로 바꿈 + if (now_node, next_node) in {(g, h), (h, g)}: new_flag = 0 + + heappush(heap, [now_cost + cost, next_node, new_flag]) + + answer = [] + for dedication in node_dedications: + if flag[dedication] == 0: answer.append(dedication) + + print(*sorted(answer)) \ No newline at end of file From 71eed4e5374e2cd8448a82fc0f746c909cd508d8 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Sat, 18 May 2024 02:01:11 +0900 Subject: [PATCH 2/3] 2024-05-18 --- tgyuuAn/README.md | 1 + ...44\355\212\270\354\233\214\355\201\254.py" | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 "tgyuuAn/\354\234\240\353\213\210\354\230\250 \355\214\214\354\235\270\353\223\234/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index cbc8e16b..875c8b39 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -55,4 +55,5 @@ | 51차시 | 2023.04.07 | BFS | 과외맨 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/179 | 52차시 | 2023.05.06 | 위상정렬 | 게임 개발 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/182 | 53차시 | 2023.05.09 | 백트래킹 | 2048 (Easy) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184 +| 55차시 | 2023.05.18 | 유니온 파인드 | 친구 네트워크 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/189 --- diff --git "a/tgyuuAn/\354\234\240\353\213\210\354\230\250 \355\214\214\354\235\270\353\223\234/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254.py" "b/tgyuuAn/\354\234\240\353\213\210\354\230\250 \355\214\214\354\235\270\353\223\234/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254.py" new file mode 100644 index 00000000..4d44b637 --- /dev/null +++ "b/tgyuuAn/\354\234\240\353\213\210\354\230\250 \355\214\214\354\235\270\353\223\234/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254.py" @@ -0,0 +1,40 @@ +import sys +from collections import defaultdict + +def input(): return sys.stdin.readline().rstrip() + +def find_parent(element, graph): + if graph[element] == element: return element + + parent = graph[element] + graph[element] = find_parent(parent, graph) + return graph[element] + +def union(first, second, graph, count): + x = find_parent(first, graph) + y = find_parent(second, graph) + + if x == y: return + + x, y = min(x, y), max(x, y) + graph[y] = x + count[x] += count[y] + count[y] = 0 + return + +T = int(input()) + +for _ in range(T): + F = int(input()) + index = 1 + parent = defaultdict(str) + count = defaultdict(lambda : 1) + + for _ in range(F): + first, second = input().split() + if parent[first] == "": parent[first] = first + if parent[second] == "": parent[second] = second + if parent[first] != parent[second]: union(first, second, parent, count) + + print(count[find_parent(first, parent)]) + \ No newline at end of file From abb7a083cda17c2690ab6b219aa315acae93ffd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D=7CMinseok=20Kim?= Date: Wed, 22 May 2024 14:08:03 +0900 Subject: [PATCH 3/3] 25-alstjr7437 (#190) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 2024-05-18 문제 선정 * 2024-05-18 solved --- alstjr7437/README.md | 3 ++- "alstjr7437/\353\215\261/AC.py" | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 "alstjr7437/\353\215\261/AC.py" diff --git a/alstjr7437/README.md b/alstjr7437/README.md index c132ba86..de60cec6 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -25,4 +25,5 @@ | 21차시 | 2024.04.06 | 비트마스킹 | 집합 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/74 | | 22차시 | 2024.04.13 | BFS | 연결 요소의 개수 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 | | 23차시 | 2024.05.01 | 큐 | 프로세스 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/79 | -| 24차시 | 2024.05.14 | BFS | 토마토 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/187 | \ No newline at end of file +| 24차시 | 2024.05.14 | BFS | 토마토 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/187 | +| 25차시 | 2024.05.18 | 덱 | AC | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/190 | \ No newline at end of file diff --git "a/alstjr7437/\353\215\261/AC.py" "b/alstjr7437/\353\215\261/AC.py" new file mode 100644 index 00000000..3bbb6479 --- /dev/null +++ "b/alstjr7437/\353\215\261/AC.py" @@ -0,0 +1,41 @@ +from collections import deque +import sys +input = sys.stdin.readline + +t = int(input()) + +for _ in range(t): + temp_reverse = False + error = 0 + + p = input() + n = int(input()) + x = deque(input().strip()[1:-1].split(',')) + + if n == 0 : + x = deque() + + for i in p: + if i == 'R': + if temp_reverse : + temp_reverse = False + else : + temp_reverse = True + + if i == "D": + if len(x) == 0: + error = 1 + break + else : + if temp_reverse : + x.pop() + else : + x.popleft() + + if temp_reverse : + x.reverse() + + if error == 0 : + print(f"[{','.join(str(i) for i in x)}]") + else : + print("error")