For problem statement at 1000-1999/1200-1299/1250-1259/1250/problemE.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1250-1259/1250/verifierE.go ends with All 100 tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
)
func main() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
var t int
if _, err := fmt.Fscan(in, &t); err != nil {
return
}
for tc := 0; tc < t; tc++ {
var n, m, k int
fmt.Fscan(in, &n, &m, &k)
s := make([]string, n)
for i := 0; i < n; i++ {
fmt.Fscan(in, &s[i])
}
adj := make([][]struct {
to int
w int
}, n)
possible := true
for i := 0; i < n; i++ {
for j := i + 1; j < n; j++ {
sameCount := 0
diffCount := 0
for p := 0; p < m; p++ {
if s[i][p] == s[j][p] {
sameCount++
}
if s[i][p] == s[j][m-1-p] {
diffCount++
}
}
sameOk := sameCount >= k
diffOk := diffCount >= k
if !sameOk && !diffOk {
possible = false
} else if sameOk && !diffOk {
adj[i] = append(adj[i], struct{ to, w int }{j, 0})
adj[j] = append(adj[j], struct{ to, w int }{i, 0})
} else if !sameOk && diffOk {
adj[i] = append(adj[i], struct{ to, w int }{j, 1})
adj[j] = append(adj[j], struct{ to, w int }{i, 1})
}
}
}
if !possible {
fmt.Fprintln(out, -1)
continue
}
color := make([]int, n)
for i := range color {
color[i] = -1
}
ans := []int{}
for i := 0; i < n; i++ {
if color[i] == -1 {
compNodes := []int{}
queue := []int{i}
color[i] = 0
for len(queue) > 0 {
u := queue[0]
queue = queue[1:]
compNodes = append(compNodes, u)
for _, edge := range adj[u] {
v := edge.to
w := edge.w
if color[v] == -1 {
color[v] = color[u] ^ w
queue = append(queue, v)
} else if color[v] != color[u]^w {
possible = false
}
}
}
if !possible {
break
}
count1 := 0
for _, v := range compNodes {
if color[v] == 1 {
count1++
}
}
count0 := len(compNodes) - count1
if count1 > count0 {
for _, v := range compNodes {
color[v] ^= 1
}
}
for _, v := range compNodes {
if color[v] == 1 {
ans = append(ans, v+1)
}
}
}
}
if !possible {
fmt.Fprintln(out, -1)
continue
}
fmt.Fprintln(out, len(ans))
if len(ans) == 0 {
fmt.Fprintln(out)
} else {
for idx, val := range ans {
if idx > 0 {
fmt.Fprint(out, " ")
}
fmt.Fprint(out, val)
}
fmt.Fprintln(out)
}
}
}