Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

플로이드 알고리즘(Floyd-Warshall) #28

Closed
Taehyeon-Kim opened this issue Jan 20, 2023 · 0 comments
Closed

플로이드 알고리즘(Floyd-Warshall) #28

Taehyeon-Kim opened this issue Jan 20, 2023 · 0 comments

Comments

@Taehyeon-Kim
Copy link
Owner

Taehyeon-Kim commented Jan 20, 2023

플로이드 알고리즘

모든 정점 쌍 사이의 최단 거리를 구하는 알고리즘

let n = 5
let d = [[], [] ,[], [] ,[]] // 예시이므로 값을 채워놓지는 않았음

// 최단거리 테이블 초기화
// 1. 자기 자신으로 가는 거리는 0
// 2. 가지 못하는 곳은 Int.max(무한을 의미)
/* code */

// k가 가장 바깥에서 루프를 도는 것은 자명한 사실이다.
for k in 0..<n {
  for s in 0..<n {
    for t in 0..<n {
      d[s][t] = min(d[s][t], d[s][k] + d[k][t])
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant