For problem statement at 0-999/700-799/780-789/780/problemF.txt this is a correct solution, but verifier at 0-999/700-799/780-789/780/verifierF.go ends with All tests passed can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"io"
"math/bits"
"os"
)
type Matrix [][]uint64
const (
MAXK = 60
LIMIT = uint64(1000000000000000000)
)
var (
n int
words int
mats [2][]Matrix
)
func newMatrix(n, words int) Matrix {
data := make([]uint64, n*words)
m := make(Matrix, n)
for i := 0; i < n; i++ {
m[i] = data[i*words : (i+1)*words]
}
return m
}
func matMul(a, b Matrix) Matrix {
c := newMatrix(n, words)
for i := 0; i < n; i++ {
rowA := a[i]
rowC := c[i]
for wi, word := range rowA {
x := word
for x != 0 {
bit := bits.TrailingZeros64(x)
idx := wi*64 + bit
rowB := b[idx]
for j := 0; j < words; j++ {
rowC[j] |= rowB[j]
}
x &= x - 1
}
}
}
return c
}
func applyMatrix(vec []uint64, m Matrix) []uint64 {
res := make([]uint64, words)
for wi, word := range vec {
x := word
for x != 0 {
bit := bits.TrailingZeros64(x)
idx := wi*64 + bit
row := m[idx]
for j := 0; j < words; j++ {
res[j] |= row[j]
}
x &= x - 1
}
}
return res
}
func nonEmpty(vec []uint64) bool {
for _, x := range vec {
if x != 0 {
return true
}
}
return false
}
func reach(vec []uint64, c, k int, length uint64) []uint64 {
if length == 0 {
return vec
}
if k == 0 {
return applyMatrix(vec, mats[c][0])
}
half := uint64(1) << uint(k-1)
if length <= half {
return reach(vec, c, k-1, length)
}
vec = applyMatrix(vec, mats[c][k-1])
if !nonEmpty(vec) {
return vec
}
return reach(vec, c^1, k-1, length-half)
}
func reachable(length uint64) bool {
if length == 0 {
return true
}
vec := make([]uint64, words)
vec[0] = 1
vec = reach(vec, 0, MAXK, length)
return nonEmpty(vec)
}
func main() {
data, _ := io.ReadAll(os.Stdin)
p := 0
nextInt := func() int {
for p < len(data) && (data[p] < '0' || data[p] > '9') {
p++
}
v := 0
for p < len(data) && data[p] >= '0' && data[p] <= '9' {
v = v*10 + int(data[p]-'0')
p++
}
return v
}
n = nextInt()
m := nextInt()
words = (n + 63) >> 6
mats[0] = make([]Matrix, MAXK+1)
mats[1] = make([]Matrix, MAXK+1)
mats[0][0] = newMatrix(n, words)
mats[1][0] = newMatrix(n, words)
for i := 0; i < m; i++ {
v := nextInt() - 1
u := nextInt() - 1
t := nextInt()
mats[t][0][v][u>>6] |= uint64(1) << uint(u&63)
}
for k := 0; k < MAXK; k++ {
mats[0][k+1] = matMul(mats[0][k], mats[1][k])
mats[1][k+1] = matMul(mats[1][k], mats[0][k])
}
out := bufio.NewWriterSize(os.Stdout, 1<<20)
defer out.Flush()
if reachable(LIMIT + 1) {
fmt.Fprintln(out, -1)
return
}
lo, hi := uint64(0), LIMIT
for lo < hi {
mid := lo + (hi-lo+1)/2
if reachable(mid) {
lo = mid
} else {
hi = mid - 1
}
}
fmt.Fprintln(out, lo)
}
```