[Swift: 깊이/너비 우선 탐색(DFS/BFS)] 1260번 - DFS와 BFS


[Swift: 깊이/너비 우선 탐색(DFS/BFS)] 1260번 - DFS와 BFS

let inputs = readLine()!.split(separator: " ").map(){Int(String($0))!} let n = inputs[0] let m = inputs[1] let v = inputs[2] var graph = [[Int]](repeating: [], count: n) graph.append([]) for _ in 0..<m { let arr = readLine()!.split(separator: " ").map(){Int(String($0))!} graph[arr[0]].append(arr[1]) graph[arr[0]] = graph[arr[0]].sorted(by: <) graph[arr[1]].append(arr[0]) graph[arr[1]] = graph[arr[1]].sorted(by: <) } var visited = [Bool](repeating: false, count: n+1) func dfs(_ start: Int) { visi...



원문링크 : [Swift: 깊이/너비 우선 탐색(DFS/BFS)] 1260번 - DFS와 BFS