Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

49-tgyuuAn #174

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tgyuuAn/DP/KCM Travel.py
Original file line number Diff line number Diff line change
@@ -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)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λͺ‡ κΈ€μž 차이 μ•ˆλ‚˜κΈ΄ ν•˜μ§€λ§Œ,, INF = int(1e9)둜 λ”°λ‘œ λ‘λŠ”κ²Œ μ–΄λ–¨κΉŒμš”?
int(1e9)κ°€ 자주 μ‚¬μš©λ˜λ‹ˆ INF둜 λ”°λ‘œ μƒμˆ˜λ‘œ 빼두면 가독성이 더 μ’‹μ•„μ§ˆ 것 κ°™μŠ΅λ‹ˆλ‹€ 😎

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν—‰ μ™„μ „ λ™μ˜ν•©λ‹ˆλ‹€....! 😁😁😁

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")
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@
| 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
| 44μ°¨μ‹œ | 2023.03.13 | 트라이 | <a href="https://www.acmicpc.net/problem/14725">개미꡴</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
| 45μ°¨μ‹œ | 2023.03.16 | 트라이 | <a href="https://www.acmicpc.net/problem/31413">트라이</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
| 49μ°¨μ‹œ | 2023.03.29 | DP | <a href="https://www.acmicpc.net/problem/10217">KCM Travel</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/174
---