Skip to content

Commit

Permalink
2024-09-04
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu committed Sep 4, 2024
1 parent 39a3ee2 commit bfd887e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
10 changes: 6 additions & 4 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
| 20์ฐจ์‹œ | 2024.06.03 | ๋ฐฑํŠธ๋ž˜ํ‚น | [์Šคํƒ€ํŠธ์™€ ๋งํฌ](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 |
| 21์ฐจ์‹œ | 2024.06.07 | ๊ทธ๋ฆฌ๋”” | [ํ–‰๋ณต ์œ ์น˜์›](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 |
| 22์ฐจ์‹œ | 2024.08.06 | ํ•ด์‹œ | [์˜์ƒ](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 |
| 23์ฐจ์‹œ | 2024.08.10 | ํ•ด์‹œ | [๋ฒ ์ŠคํŠธ์•จ๋ฒ”](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 |
| 24์ฐจ์‹œ | 2024.08.17 | BFS | [์•„๊ธฐ์ƒ์–ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 |
| 25์ฐจ์‹œ | 2024.08.17 | DFS | [์นœ๊ตฌ๋น„](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 |
| 26์ฐจ์‹œ | 2024.08.24 | ๊ทธ๋ฆฌ๋”” | [์‹ ์ž…์‚ฌ์›](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 |
| 23์ฐจ์‹œ | 2024.08.10 | ํ•ด์‹œ | [๋ฒ ์ŠคํŠธ์•จ๋ฒ”](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 |
| 24์ฐจ์‹œ | 2024.08.17 | BFS | [์•„๊ธฐ์ƒ์–ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 |
| 25์ฐจ์‹œ | 2024.08.17 | DFS | [์นœ๊ตฌ๋น„](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 |
| 26์ฐจ์‹œ | 2024.08.24 | ๊ทธ๋ฆฌ๋”” | [์‹ ์ž…์‚ฌ์›](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 |

| 28์ฐจ์‹œ | 2024.09.04 | ๋ฒจ๋งŒํฌ๋“œ | [ํƒ€์ž„๋จธ์‹ ](https://www.acmicpc.net/problem/11657) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/244 |

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys

INF = 1e8

def input() : return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
bus = [[] for _ in range(N+1)]
distance = [INF] * (N+1)

for i in range(M):
A, B, C = map(int, input().split())
bus[A].append([B, C])

def BellmanFord(start):
distance[start] = 0

for i in range(N):
for j in range(1, N+1):
for n, w in bus[j]:
if distance[j] != INF and distance[n] > distance[j] + w:
distance[n] = distance[j] + w
if i == N-1:
return True
return False

check_negative = BellmanFord(1)

if check_negative:
print("-1")
else:
for i in range(2, N+1):
if distance[i] == INF:
print("-1")
else:
print(distance[i])

0 comments on commit bfd887e

Please sign in to comment.