Notice
Recent Posts
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 |
Tags
- python
- php-1
- apk 빌드
- expo
- redux state값 유지
- 오블완
- 공공데이터 포털
- 코딩테스트
- 드림핵
- level3
- web-view
- 보안
- 개발
- Dreamhack
- react-router-dom
- 블로그 뉴비
- 새로고침
- 부산 맛집 OPEN API
- 훈수 가능
- React
- 티스토리챌린지
- 사업계획서
- 창업 300
- Redux
- 프로그래머스
- 고고학 최고의 발견
- API 활용 신청
- url 랜더링
- 꿀팁 환영
Archives
- Today
- Total
1223v
[BOJ] Python 플로이드(11404) 본문
https://www.acmicpc.net/problem/11404
대표적인 플로이드 워셜 문제이다.
모든 경로에서의 최단경로를 출력하는 문제이다.
3중 for 문을 통해 값을 최신화 한다.
import sys
input = sys.stdin.readline
N = int(input())
M = int(input())
graph = [[] for _ in range(N+1)]
distance = [[float('inf')]*(N+1) for _ in range(N+1)]
for i in range(1, N+1):
distance[i][i] = 0
for _ in range(M):
s,e,cost = map(int,input().split())
if distance[s][e] > cost:
distance[s][e] = cost
def floyid_func():
for k in range(1,N+1):
for i in range(1,N+1):
for j in range(1,N+1):
if distance[i][j] > distance[i][k] + distance[k][j]:
distance[i][j] = distance[i][k] + distance[k][j]
floyid_func()
for i in range(1,N+1):
for j in range(1,N+1):
if distance[i][j] == float('inf'):
distance[i][j] = 0
print(distance[i][j],end=' ')
print()
회고.
자기 자신은 0이라는 조건을 잊어버려 답이 나오지 않았었다....
728x90
'PS' 카테고리의 다른 글
[BOJ] Python 택배(1719) (0) | 2025.02.21 |
---|---|
[BOJ] Python 회문(17609) (0) | 2025.02.20 |
[Programmers] Python 파괴되지 않은 건물 (92344) (0) | 2025.02.17 |
[BOJ] Python, Ruby 백준 최소 회의실 개수 (19598) (0) | 2025.02.17 |
[Programmers] Python, Ruby 프로그래머스 불량 사용자(64064) (0) | 2025.02.15 |