← Home
For problem statement at 1000-1999/1600-1699/1670-1679/1672/problemF2.txt this is a correct solution, but verifier at 1000-1999/1600-1699/1670-1679/1672/verifierF2.go ends with All tests passed can you fix the verifier? package main

import (
	"io"
	"os"
	"strings"
)

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

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

	var out strings.Builder

	for ; t > 0; t-- {
		n := nextInt(data, &idx)
		a := make([]int, n)
		b := make([]int, n)

		freq := make([]int, n+1)
		distinct := 0
		maxFreq := 0
		m := 1

		for i := 0; i < n; i++ {
			x := nextInt(data, &idx)
			a[i] = x
			if freq[x] == 0 {
				distinct++
			}
			freq[x]++
			if freq[x] > maxFreq {
				maxFreq = freq[x]
				m = x
			}
		}

		for i := 0; i < n; i++ {
			b[i] = nextInt(data, &idx)
		}

		adj := make([][]int, n+1)
		indeg := make([]int, n+1)

		for i := 0; i < n; i++ {
			u := b[i]
			v := a[i]
			if u != m && v != m {
				adj[u] = append(adj[u], v)
				indeg[v]++
			}
		}

		queue := make([]int, 0, distinct)
		targetVertices := 0
		for v := 1; v <= n; v++ {
			if v != m && freq[v] > 0 {
				targetVertices++
				if indeg[v] == 0 {
					queue = append(queue, v)
				}
			}
		}

		processed := 0
		for head := 0; head < len(queue); head++ {
			u := queue[head]
			processed++
			for _, v := range adj[u] {
				indeg[v]--
				if indeg[v] == 0 {
					queue = append(queue, v)
				}
			}
		}

		if processed == targetVertices {
			out.WriteString("AC\n")
		} else {
			out.WriteString("WA\n")
		}
	}

	os.Stdout.WriteString(out.String())
}