← Home
For problem statement at 1000-1999/1900-1999/1910-1919/1913/problemE.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1910-1919/1913/verifierE.go ends with All 100 tests passed can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const INF = 1e9

type Edge struct {
	to   int
	rev  int
	cap  int
	flow int
	cost int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	readInt := func() int {
		scanner.Scan()
		val, _ := strconv.Atoi(scanner.Text())
		return val
	}

	if !scanner.Scan() {
		return
	}
	nStr := scanner.Text()
	n, _ := strconv.Atoi(nStr)
	m := readInt()

	a := make([][]int, n)
	baseCost := 0
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			val := readInt()
			a[i][j] = val
			if val == 1 {
				baseCost++
			}
		}
	}

	A := make([]int, n)
	sumA := 0
	for i := 0; i < n; i++ {
		A[i] = readInt()
		sumA += A[i]
	}

	B := make([]int, m)
	sumB := 0
	for i := 0; i < m; i++ {
		B[i] = readInt()
		sumB += B[i]
	}

	if sumA != sumB {
		fmt.Println("-1")
		return
	}

	source := 0
	sink := n + m + 1
	graph := make([][]Edge, sink+1)

	addEdge := func(u, v, cap, cost int) {
		graph[u] = append(graph[u], Edge{to: v, rev: len(graph[v]), cap: cap, cost: cost})
		graph[v] = append(graph[v], Edge{to: u, rev: len(graph[u]) - 1, cap: 0, cost: -cost})
	}

	for i := 0; i < n; i++ {
		addEdge(source, i+1, A[i], 0)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			cost := 0
			if a[i][j] == 0 {
				cost = 1
			} else {
				cost = -1
			}
			addEdge(i+1, n+j+1, 1, cost)
		}
	}

	for j := 0; j < m; j++ {
		addEdge(n+j+1, sink, B[j], 0)
	}

	minCost := 0
	flow := 0
	targetFlow := sumA

	dist := make([]int, sink+1)
	parentEdge := make([]int, sink+1)
	parentNode := make([]int, sink+1)
	inQueue := make([]bool, sink+1)
	q := make([]int, 0, sink+1)

	for flow < targetFlow {
		for i := range dist {
			dist[i] = int(INF)
		}
		dist[source] = 0
		
		q = q[:0]
		q = append(q, source)
		
		for i := range inQueue {
			inQueue[i] = false
		}
		inQueue[source] = true

		head := 0
		for head < len(q) {
			u := q[head]
			head++
			inQueue[u] = false

			for i := range graph[u] {
				e := &graph[u][i]
				if e.cap > e.flow && dist[e.to] > dist[u]+e.cost {
					dist[e.to] = dist[u] + e.cost
					parentNode[e.to] = u
					parentEdge[e.to] = i
					if !inQueue[e.to] {
						q = append(q, e.to)
						inQueue[e.to] = true
					}
				}
			}
		}

		if dist[sink] == int(INF) {
			fmt.Println("-1")
			return
		}

		push := targetFlow - flow
		curr := sink
		for curr != source {
			p := parentNode[curr]
			idx := parentEdge[curr]
			avail := graph[p][idx].cap - graph[p][idx].flow
			if avail < push {
				push = avail
			}
			curr = p
		}

		flow += push
		minCost += push * dist[sink]
		curr = sink
		for curr != source {
			p := parentNode[curr]
			idx := parentEdge[curr]
			graph[p][idx].flow += push
			revIdx := graph[p][idx].rev
			graph[curr][revIdx].flow -= push
			curr = p
		}
	}

	fmt.Println(baseCost + minCost)
}
```