For problem statement at 0-999/0-99/30-39/37/problemE.txt this is a correct solution, but verifier at 0-999/0-99/30-39/37/verifierE.go ends with All tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
)
type Point struct {
r, c int
}
func main() {
reader := bufio.NewReader(os.Stdin)
var N, M int
if _, err := fmt.Fscan(reader, &N, &M); err != nil {
return
}
grid := make([]string, N)
hasB := false
for i := 0; i < N; i++ {
fmt.Fscan(reader, &grid[i])
for j := 0; j < M; j++ {
if grid[i][j] == 'B' {
hasB = true
}
}
}
if !hasB {
fmt.Println(0)
return
}
ans := 1000000000
visitedComp := make([][]bool, N)
for i := 0; i < N; i++ {
visitedComp[i] = make([]bool, M)
}
dirs := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
dist := make([][]int, N)
for i := 0; i < N; i++ {
dist[i] = make([]int, M)
}
deque := make([]Point, 100000)
for i := 0; i < N; i++ {
for j := 0; j < M; j++ {
if visitedComp[i][j] {
continue
}
for r := 0; r < N; r++ {
for c := 0; c < M; c++ {
dist[r][c] = 1000000000
}
}
head, tail := 50000, 50000
deque[tail] = Point{i, j}
tail++
dist[i][j] = 0
for head < tail {
u := deque[head]
head++
if dist[u.r][u.c] == 0 {
visitedComp[u.r][u.c] = true
}
for _, d := range dirs {
nr, nc := u.r+d[0], u.c+d[1]
if nr >= 0 && nr < N && nc >= 0 && nc < M {
w := 0
if grid[u.r][u.c] != grid[nr][nc] {
w = 1
}
if dist[u.r][u.c]+w < dist[nr][nc] {
dist[nr][nc] = dist[u.r][u.c] + w
if w == 0 {
head--
deque[head] = Point{nr, nc}
} else {
deque[tail] = Point{nr, nc}
tail++
}
}
}
}
}
maxB := -1
for r := 0; r < N; r++ {
for c := 0; c < M; c++ {
if grid[r][c] == 'B' {
if dist[r][c] > maxB {
maxB = dist[r][c]
}
}
}
}
if maxB != -1 {
if maxB+1 < ans {
ans = maxB + 1
}
}
}
}
fmt.Println(ans)
}