Skip to content

Commit

Permalink
Merge pull request #58 from AlgoLeadMe/12-fnzksxl
Browse files Browse the repository at this point in the history
12-fnzksxl
  • Loading branch information
fnzksxl authored Mar 23, 2024
2 parents 9333369 + 1f1023f commit 8e79b88
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions fnzksxl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
| 9μ°¨μ‹œ | 2024-02-23 | κ·Έλž˜ν”„ | [μˆœμœ„](https://school.programmers.co.kr/learn/courses/30/lessons/49191) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/37) |
| 10μ°¨μ‹œ | 2024-03-07 | κ΅¬ν˜„ | [λ‚˜λ¬΄ μž¬ν…Œν¬](https://www.acmicpc.net/problem/16235) | [#52](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/52) |
| 11μ°¨μ‹œ | 2024-03-10 | νˆ¬ν¬μΈν„° | [보석 μ‡Όν•‘](https://school.programmers.co.kr/learn/courses/30/lessons/67258) | [#56](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/56) |
| 12μ°¨μ‹œ | 2024-03-13 | λ²¨λ§Œν¬λ“œ | [νƒ€μž„λ¨Έμ‹ ](https://www.acmicpc.net/problem/11657) | [#](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/58) |
---
38 changes: 38 additions & 0 deletions fnzksxl/λ²¨λ§Œν¬λ“œ/νƒ€μž„λ¨Έμ‹ .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys

input = sys.stdin.readline


def func():
distances[1] = 0

for i in range(N):
for j in range(M):
cur_node, next_node, weight = edges[j]
if distances[cur_node] != float('inf') and distances[next_node] > distances[cur_node] + weight:
distances[next_node] = distances[cur_node] + weight
if i == N-1:
return False

return True


N, M = map(int, input().split())

edges = []
distances = [float('inf')] * (N+1)
q = []

for _ in range(M):
start, end, weight = map(int, input().split())
edges.append((start, end, weight))


if func():
for weight in distances[2:]:
if weight == float('inf'):
print(-1)
else:
print(weight)
else:
print(-1)

0 comments on commit 8e79b88

Please sign in to comment.