← Home
For problem statement at 0-999/900-999/990-999/999/problemE.txt this is a correct solution, but verifier at 0-999/900-999/990-999/999/verifierE.go ends with reference failed: exec: "refE.bin": executable file not found in $PATH
stderr: 
exit status 1 can you fix the verifier? package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	buf, _ := io.ReadAll(os.Stdin)
	var pos int

	nextInt := func() int {
		for pos < len(buf) && (buf[pos] < '0' || buf[pos] > '9') {
			pos++
		}
		if pos >= len(buf) {
			return 0
		}
		res := 0
		for pos < len(buf) && buf[pos] >= '0' && buf[pos] <= '9' {
			res = res*10 + int(buf[pos]-'0')
			pos++
		}
		return res
	}

	n := nextInt()
	if n == 0 {
		return
	}
	m := nextInt()
	s := nextInt()

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

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

	visited := make([]bool, n+1)
	order := make([]int, 0, n)

	var dfs1 func(int)
	dfs1 = func(u int) {
		visited[u] = true
		for _, v := range adj[u] {
			if !visited[v] {
				dfs1(v)
			}
		}
		order = append(order, u)
	}

	for i := 1; i <= n; i++ {
		if !visited[i] {
			dfs1(i)
		}
	}

	scc := make([]int, n+1)
	for i := 1; i <= n; i++ {
		visited[i] = false
	}

	var dfs2 func(int, int)
	dfs2 = func(u, c int) {
		visited[u] = true
		scc[u] = c
		for _, v := range rev[u] {
			if !visited[v] {
				dfs2(v, c)
			}
		}
	}

	count := 0
	for i := n - 1; i >= 0; i-- {
		u := order[i]
		if !visited[u] {
			count++
			dfs2(u, count)
		}
	}

	inDegree := make([]int, count+1)
	for u := 1; u <= n; u++ {
		for _, v := range adj[u] {
			if scc[u] != scc[v] {
				inDegree[scc[v]]++
			}
		}
	}

	ans := 0
	for i := 1; i <= count; i++ {
		if inDegree[i] == 0 && i != scc[s] {
			ans++
		}
	}

	fmt.Println(ans)
}