← Home
For problem statement at 1000-1999/1300-1399/1320-1329/1320/problemB.txt this is a correct solution, but verifier at 1000-1999/1300-1399/1320-1329/1320/verifierB.go ends with All 15 tests passed. can you fix the verifier? package main

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

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

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

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

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

	for i := 0; i < m; i++ {
		u, v := scanInt(), scanInt()
		adj[u] = append(adj[u], v)
		revAdj[v] = append(revAdj[v], u)
	}

	k := scanInt()
	path := make([]int, k)
	for i := 0; i < k; i++ {
		path[i] = scanInt()
	}

	t := path[k-1]
	dist := make([]int, n+1)
	for i := 1; i <= n; i++ {
		dist[i] = -1
	}

	queue := make([]int, 0, n)
	queue = append(queue, t)
	dist[t] = 0

	for head := 0; head < len(queue); head++ {
		curr := queue[head]
		for _, next := range revAdj[curr] {
			if dist[next] == -1 {
				dist[next] = dist[curr] + 1
				queue = append(queue, next)
			}
		}
	}

	minRebuilds, maxRebuilds := 0, 0
	for i := 0; i < k-1; i++ {
		u, w := path[i], path[i+1]
		if dist[w] != dist[u]-1 {
			minRebuilds++
			maxRebuilds++
		} else {
			for _, v := range adj[u] {
				if v != w && dist[v] == dist[u]-1 {
					maxRebuilds++
					break
				}
			}
		}
	}

	fmt.Printf("%d %d\n", minRebuilds, maxRebuilds)
}