← Home
For problem statement at 1000-1999/1900-1999/1950-1959/1950/problemG.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1950-1959/1950/verifierG.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 1024*1024)
	scanner.Buffer(buf, 1024*1024)
	scanner.Split(bufio.ScanWords)

	readString := func() string {
		scanner.Scan()
		return scanner.Text()
	}

	readInt := func() int {
		scanner.Scan()
		res := 0
		for _, b := range scanner.Bytes() {
			res = res*10 + int(b-'0')
		}
		return res
	}

	if !scanner.Scan() {
		return
	}
	t := 0
	for _, b := range scanner.Bytes() {
		t = t*10 + int(b-'0')
	}

	dp := make([]int, 1<<16)
	g := make([]string, 16)
	w := make([]string, 16)
	adj := make([]int, 16)

	for i := 0; i < t; i++ {
		n := readInt()
		for j := 0; j < n; j++ {
			g[j] = readString()
			w[j] = readString()
			adj[j] = 0
		}

		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				if j != k && (g[j] == g[k] || w[j] == w[k]) {
					adj[j] |= (1 << k)
				}
			}
		}

		limit := 1 << n
		for j := 0; j < limit; j++ {
			dp[j] = 0
		}
		for j := 0; j < n; j++ {
			dp[1<<j] = 1 << j
		}

		maxSongs := 0
		for mask := 1; mask < limit; mask++ {
			if dp[mask] == 0 {
				continue
			}
			c := bits.OnesCount(uint(mask))
			if c > maxSongs {
				maxSongs = c
			}
			validLasts := uint(dp[mask])
			for validLasts > 0 {
				last := bits.TrailingZeros(validLasts)
				nexts := uint(adj[last] & ^mask)
				for nexts > 0 {
					next := bits.TrailingZeros(nexts)
					dp[mask|(1<<next)] |= (1 << next)
					nexts &= nexts - 1
				}
				validLasts &= validLasts - 1
			}
		}
		fmt.Println(n - maxSongs)
	}
}
```