func readInt2() -> (Int16, Int16) { let l = readLine()!.split(separator: " ").map{Int16($0)!} return (l[0], l[1]) } func readLines(_ n: Int16) -> [[Bool]] { return (0.. [Bool] in return readLine()!.split(separator: " ").map{$0 == "1"} } } let (H, W) = readInt2() var A = readLines(H) let dires: [(Int16, Int16)] = [(-1, 0),(0, 1),(1, 0),(0, -1)] func dfs(_ i: Int16, _ j: Int16) -> Int{ var frontier = ArraySlice<(Int16, Int16)>() frontier.append((i, j)) while let (h, w) = frontier.popFirst() { A[Int(h)][Int(w)] = false for (y, x) in dires { let sucY = h+y let sucX = w+x if sucY < 0 || sucY >= H || sucX < 0 || sucX >= W || !A[Int(sucY)][Int(sucX)] { continue } frontier.append((sucY, sucX)) } } return 1 } func test() { var ans = 0 for i in 0..