-
Notifications
You must be signed in to change notification settings - Fork 0
플로이드 #132
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
Merged
Merged
플로이드 #132
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // 백준 - 11404 플로이드 | ||
|
|
||
| let cityCount = Int(readLine()!)! | ||
| let busCount = Int(readLine()!)! | ||
| let basic = [Int](repeating: .max, count: cityCount+1) | ||
| var graph = [[Int]](repeating: basic, count: cityCount+1) | ||
|
|
||
| for _ in 1...busCount { | ||
| let line = readLine()!.split(separator: " ").compactMap { Int($0) } | ||
| graph[line[0]][line[1]] = min(graph[line[0]][line[1]], line[2]) | ||
| } | ||
|
|
||
| for city in 1...cityCount { | ||
| graph[city][city] = 0 | ||
| for start in 1...cityCount where graph[start][city] != Int.max { | ||
| for end in 1...cityCount where graph[city][end] != Int.max { | ||
| let newWeight = graph[start][city] + graph[city][end] | ||
| if graph[start][end] > newWeight { graph[start][end] = newWeight } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for i in 1...cityCount { | ||
| print((1...cityCount).map { | ||
| graph[i][$0] == Int.max ? "0" : String(graph[i][$0]) | ||
| }.joined(separator: " ")) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
입력 데이터의 양($M \le 100,000$ )이 많을 때
readLine()과split을 반복적으로 호출하는 것은 Swift에서 성능 저하의 주요 원인이 될 수 있습니다. 현재 문제의 시간 제한(2초) 내에는 통과할 가능성이 높지만, 데이터가 더 많거나 시간 제한이 촉박한 경우에는FileIO와 같은 더 빠른 입력 방식을 사용하는 것이 권장됩니다.