Skip to content

Commit 4bb0d01

Browse files
committed
2024-03-29
1 parent 91b36eb commit 4bb0d01

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tgyuuAn/DP/KCM Travel.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from collections import defaultdict, deque
2+
import sys
3+
4+
def input(): return sys.stdin.readline().rstrip()
5+
6+
T = int(input())
7+
for _ in range(T):
8+
N, M, K = map(int, input().split())
9+
10+
costs = [[int(1e9) for _ in range(M+1)] for _ in range(N+1)]
11+
costs[1][0] = 0
12+
13+
graph = [[] for _ in range(N+1)]
14+
for _ in range(K):
15+
start, destination, cost, duration = map(int,input().split())
16+
graph[start].append((destination, cost, duration))
17+
18+
# print(edges)
19+
20+
for cost in range(M+1):
21+
for city in range(1, N):
22+
if costs[city][cost] == int(1e9): continue
23+
24+
for now_destination, now_cost, now_duration in graph[city]:
25+
26+
if now_cost + cost <= M and costs[now_destination][cost + now_cost] > costs[city][cost] + now_duration:
27+
costs[now_destination][cost + now_cost] = costs[city][cost] + now_duration
28+
29+
result = min(costs[N])
30+
print(result) if result != int(1e9) else print("Poor KCM")

tgyuuAn/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@
4747
| 43차시 | 2024.03.10 | 이분 탐색 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/64062">징검다리 건너기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/157
4848
| 44차시 | 2023.03.13 | 트라이 | <a href="https://www.acmicpc.net/problem/14725">개미굴</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
4949
| 45차시 | 2023.03.16 | 트라이 | <a href="https://www.acmicpc.net/problem/31413">트라이</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
50+
| 49차시 | 2023.03.29 | DP | <a href="https://www.acmicpc.net/problem/10217">KCM Travel</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/174
5051
---

0 commit comments

Comments
 (0)