반응형
Recent Posts
Notice
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 활성화 함수
- til
- dfs
- 개발자 취업
- 코딩테스트준비
- 99클럽
- 큐
- Python
- 알고리즘
- 파이썬
- leetcode
- easy 딥러닝
- 딥러닝
- 백준
- softeer
- 항해99
- 스택
- 구현
- 기능개발
- 코딩테스트 준비
- 99항해
- 해시
- python 2309
- 개발자취업
- 프로그래머스
- BOJ
- boj 2309
- 백준 2309
- BFS
- 혁펜하임
Archives
- Today
- Total
동까의 코딩
99클럽 코테 스터디 1일차 TIL 본문
반응형
https://www.acmicpc.net/problem/11657
import sys
input = sys.stdin.readline
INF = int(1e9)
def bellman_ford(start):
dist[start] = 0
for i in range(1, n + 1):
for j in range(m):
now, next, cost = edges[j][0], edges[j][1], edges[j][2]
if dist[now] != INF and dist[next] > dist[now] + cost:
dist[next] = dist[now] + cost
if i == n:
return True
return False
n, m = map(int, input().split())
edges = []
dist = [INF] * (n + 1)
for _ in range(m):
a, b, c = map(int, input().split())
edges.append((a, b, c))
negative_cycle = bellman_ford(1)
if negative_cycle:
print(-1)
else:
for i in range(2, n + 1):
if dist[i] == INF:
print(-1)
else:
print(dist[i])
오늘의 문제로 타임머신을 풀어보았습니다.
그래프 이론, 최단 경로, 벨만-포드 관련 알고리즘이 필요한 문제였습니다.
더 공부해서 따로 정리해보도록 하겠습니다.
반응형
'문제 풀이 > 99클럽' 카테고리의 다른 글
99클럽 코테 스터디 3일차 TIL (0) | 2025.01.16 |
---|---|
99클럽 코테 스터디 2일차 TIL (1) | 2025.01.14 |
[99항해] 39일차 TIL (0) | 2024.06.28 |
[99클럽] 38일차 TIL (0) | 2024.06.28 |
[99클럽] 37일차 TIL (0) | 2024.06.26 |