diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 6883eb7..ad6f690 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -86,5 +86,6 @@ | 82차시 | 2024.11.22 | 희소 배열 | 합성함수와 쿼리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/257 | 83차시 | 2024.12.01 | 수학 + 구현 | 칵테일 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/259 | 84차시 | 2024.12.31 | BFS | 불! | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261 +| 85차시 | 2025.01.09 | 다익스트라 + 이분 탐색 | 인터넷 설치 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/264 | 86차시 | 2025.01.16 | 이분 탐색 | 통나무 자르기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/265 --- diff --git "a/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230.py" "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230.py" new file mode 100644 index 0000000..5773bb3 --- /dev/null +++ "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230.py" @@ -0,0 +1,66 @@ +import sys +from heapq import * + +def input(): return sys.stdin.readline().rstrip() + +N, P, K = map(int, input().split()) +graph = [[int(1e9) for _ in range(N+1)] for _ in range(N+1)] + +for _ in range(P): + start, destination, cost = map(int, input().split()) + graph[start][destination] = min(graph[start][destination], cost) + graph[destination][start] = min(graph[destination][start], cost) + +def check(mid): + if dijkstra(mid): return True + return False + +def dijkstra(_max): + visited = set() + DP = [[int(1e9) for _ in range(K+1)] for _ in range(N+1)] + DP[1][K] = 0 + + # 간선 코스트, 남은 기회, 현재 노드 + heap = [(0, K, 1)] + while heap: + now_cost, now_remain, now_node = heappop(heap) + + if (now_node, now_remain) in visited: continue + visited.add((now_node, now_remain)) + + if DP[now_node][now_remain] < now_cost: continue + DP[now_node][now_remain] = now_cost + + if now_node == N: + return True + + for idx, cost in enumerate(graph[now_node]): + if idx == 0: continue + if cost == int(1e9): continue + + if cost <= _max: + if (idx, now_remain) in visited: continue + if DP[idx][now_remain] > cost: heappush(heap, (cost, now_remain, idx)) + + elif cost > _max and now_remain >= 1: + if (idx, now_remain-1) in visited: continue + if DP[idx][now_remain-1] > cost: heappush(heap, (cost, now_remain-1, idx)) + + for idx in range(1, K+1): + if DP[N][idx] != int(1e9): return True + + return False + +answer = int(1e9) +left = -1 +right = 1_000_001 +while left+1