diff --git a/tgyuuAn/DP/KCM Travel.py b/tgyuuAn/DP/KCM Travel.py new file mode 100644 index 00000000..4e279062 --- /dev/null +++ b/tgyuuAn/DP/KCM Travel.py @@ -0,0 +1,30 @@ +from collections import defaultdict, deque +import sys + +def input(): return sys.stdin.readline().rstrip() + +T = int(input()) +for _ in range(T): + N, M, K = map(int, input().split()) + + costs = [[int(1e9) for _ in range(M+1)] for _ in range(N+1)] + costs[1][0] = 0 + + graph = [[] for _ in range(N+1)] + for _ in range(K): + start, destination, cost, duration = map(int,input().split()) + graph[start].append((destination, cost, duration)) + + # print(edges) + + for cost in range(M+1): + for city in range(1, N): + if costs[city][cost] == int(1e9): continue + + for now_destination, now_cost, now_duration in graph[city]: + + if now_cost + cost <= M and costs[now_destination][cost + now_cost] > costs[city][cost] + now_duration: + costs[now_destination][cost + now_cost] = costs[city][cost] + now_duration + + result = min(costs[N]) + print(result) if result != int(1e9) else print("Poor KCM") \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index eea140d7..810a134b 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -50,4 +50,5 @@ | 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 ---