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