← Home
For problem statement at 1000-1999/1900-1999/1920-1929/1926/problemG.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1920-1929/1926/verifierG.go ends with ok can you fix the verifier? ```go
package main

import (
	"bufio"
	"io"
	"os"
	"strconv"
)

func main() {
	data, _ := io.ReadAll(os.Stdin)
	idx := 0

	nextInt := func() int {
		for idx < len(data) && (data[idx] == ' ' || data[idx] == '\n' || data[idx] == '\r' || data[idx] == '\t') {
			idx++
		}
		x := 0
		for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
			x = x*10 + int(data[idx]-'0')
			idx++
		}
		return x
	}

	nextString := func() string {
		for idx < len(data) && (data[idx] == ' ' || data[idx] == '\n' || data[idx] == '\r' || data[idx] == '\t') {
			idx++
		}
		start := idx
		for idx < len(data) && data[idx] != ' ' && data[idx] != '\n' && data[idx] != '\r' && data[idx] != '\t' {
			idx++
		}
		return string(data[start:idx])
	}

	t := nextInt()
	const inf = int(1 << 30)

	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	for ; t > 0; t-- {
		n := nextInt()
		children := make([][]int, n+1)
		for i := 2; i <= n; i++ {
			p := nextInt()
			children[p] = append(children[p], i)
		}
		s := nextString()

		dp := make([][3]int, n+1)

		for u := n; u >= 1; u-- {
			cur := [3]int{inf, inf, inf}
			switch s[u-1] {
			case 'C':
				cur[0] = 0
			case 'P':
				cur[1] = 0
			case 'S':
				cur[2] = 0
			}

			for _, v := range children[u] {
				ch := dp[v]
				cut := ch[0]
				if ch[1] < cut {
					cut = ch[1]
				}
				if ch[2] < cut {
					cut = ch[2]
				}
				cut++

				nxt := [3]int{inf, inf, inf}

				if cur[0] < inf {
					x := cur[0]
					if x+cut < nxt[0] {
						nxt[0] = x + cut
					}
					if x+ch[0] < nxt[0] {
						nxt[0] = x + ch[0]
					}
					if x+ch[1] < nxt[1] {
						nxt[1] = x + ch[1]
					}
					if x+ch[2] < nxt[2] {
						nxt[2] = x + ch[2]
					}
				}
				if cur[1] < inf {
					x := cur[1]
					if x+cut < nxt[1] {
						nxt[1] = x + cut
					}
					if x+ch[0] < nxt[1] {
						nxt[1] = x + ch[0]
					}
					if x+ch[1] < nxt[1] {
						nxt[1] = x + ch[1]
					}
				}
				if cur[2] < inf {
					x := cur[2]
					if x+cut < nxt[2] {
						nxt[2] = x + cut
					}
					if x+ch[0] < nxt[2] {
						nxt[2] = x + ch[0]
					}
					if x+ch[2] < nxt[2] {
						nxt[2] = x + ch[2]
					}
				}

				cur = nxt
			}

			dp[u] = cur
		}

		ans := dp[1][0]
		if dp[1][1] < ans {
			ans = dp[1][1]
		}
		if dp[1][2] < ans {
			ans = dp[1][2]
		}

		out.WriteString(strconv.Itoa(ans))
		out.WriteByte('\n')
	}
}
```