From f626b5a7cf46fe1525d8cd31c4a5b4553d342e7f Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Tue, 14 Apr 2026 11:16:22 +0900 Subject: [PATCH] Create liv.swift --- .../liv.swift" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "WEEK11/\353\260\261\354\244\200_11404_\355\224\214\353\241\234\354\235\264\353\223\234/liv.swift" diff --git "a/WEEK11/\353\260\261\354\244\200_11404_\355\224\214\353\241\234\354\235\264\353\223\234/liv.swift" "b/WEEK11/\353\260\261\354\244\200_11404_\355\224\214\353\241\234\354\235\264\353\223\234/liv.swift" new file mode 100644 index 0000000..285bff4 --- /dev/null +++ "b/WEEK11/\353\260\261\354\244\200_11404_\355\224\214\353\241\234\354\235\264\353\223\234/liv.swift" @@ -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: " ")) +}