[백준 바킹독] 0x09 - BFS 토마토(7576)
Introduction
그래프에서 모든 꼭짓점 사이의 최단 경로의 거리를 구하는 알고리즘.
음수 가중치를 갖는 간선도 순환만 없다면 잘 처리된다.
시간 복잡도는 O(V^3)이다
import sys
input = sys.stdin.readline
n = int(input())
m = int(input())
# 인접행렬 생성
INF = (1e9)
min_dist_table = [[INF]*(n+1) for _ in range(n+1)]
for a in range(1, n+1):
for b in range(1, n+1):
if a == b:
min_dist_table[a][b] =0
for _ in range(m):
a, b, c = map(int,input().split())
min_dist_table[a][b] = min(min_dist_table[a][b],c)
## 플로이드 워셜 알고리즘 (점화식 기반)
# 경로
for k in range(1, n+1):
# 출발
for a in range(1, n+1):
# 도착
for b in range(1, n+1):
min_dist_table[a][b] = min(min_dist_table[a][b], min_dist_table[a][k] + min_dist_table[k][b])
# 결과 출력
for a in range(1, n + 1):
for b in range(1, n +1):
# 노드를 방문할 수 없는 경우, '무한' 값 출력
if min_dist_table[a][b] == INF:
print(0, end = ' ')
else:
# 노드를 방문할 수 있을 경우 최단 거리 출력
print(min_dist_table[a][b], end = ' ')
# 개행1
print()
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
1167 트리의 지름
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Git 명령어를 사용한 하위 디렉토리 다운로드 Clone 할 로컬 저장소 생성
Introduction
# Fetch the submodule commits into the main repository git remote add submodule_origin git://url/to/submodule/origin git fetch submodule_origin
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Graph
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Spring Project
the page for java
가벼운 Base image를 사용
version: 3.0.0a10
WIDTH
version: 3.0.0a10
#include <iostream> #include <thread> #include <chrono> #include <mutex> #include <atomic> #include <string.h>
version: 3.0.0a10
https://cplusplus.com/reference/future/
Multithreading support was introduced in C++11.
how to costom github blog using jekyll
You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different wa...