For problem statement at 0-999/800-899/880-889/883/problemG.txt this is a correct solution, but verifier at 0-999/800-899/880-889/883/verifierG.go ends with all tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
)
type Edge struct {
to int32
id int32
typ int8 // 0: directed, 1: undirected original, 2: undirected reverse
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
scanner.Buffer(make([]byte, 1024*1024), 1024*1024*10)
nextInt := func() int32 {
scanner.Scan()
res := int32(0)
for _, b := range scanner.Bytes() {
res = res*10 + int32(b-'0')
}
return res
}
n := nextInt()
m := nextInt()
s := nextInt()
adjMixed := make([][]Edge, n+1)
adjDir := make([][]int32, n+1)
undirEdges := make([][2]int32, 0, m)
undirId := int32(0)
for i := int32(0); i < m; i++ {
t := nextInt()
u := nextInt()
v := nextInt()
if t == 1 {
adjDir[u] = append(adjDir[u], v)
adjMixed[u] = append(adjMixed[u], Edge{to: v, id: -1, typ: 0})
} else {
adjMixed[u] = append(adjMixed[u], Edge{to: v, id: undirId, typ: 1})
adjMixed[v] = append(adjMixed[v], Edge{to: u, id: undirId, typ: 2})
undirEdges = append(undirEdges, [2]int32{u, v})
undirId++
}
}
visMax := make([]bool, n+1)
visMax[s] = true
qMax := make([]int32, 0, n)
qMax = append(qMax, s)
ansMax := make([]byte, undirId)
for i := int32(0); i < undirId; i++ {
ansMax[i] = '+'
}
headMax := 0
for headMax < len(qMax) {
u := qMax[headMax]
headMax++
for _, e := range adjMixed[u] {
if !visMax[e.to] {
visMax[e.to] = true
if e.typ == 1 {
ansMax[e.id] = '+'
} else if e.typ == 2 {
ansMax[e.id] = '-'
}
qMax = append(qMax, e.to)
}
}
}
visMin := make([]bool, n+1)
visMin[s] = true
qMin := make([]int32, 0, n)
qMin = append(qMin, s)
ansMin := make([]byte, undirId)
for i := int32(0); i < undirId; i++ {
ansMin[i] = '+'
}
headMin := 0
for headMin < len(qMin) {
u := qMin[headMin]
headMin++
for _, v := range adjDir[u] {
if !visMin[v] {
visMin[v] = true
qMin = append(qMin, v)
}
}
}
for id := int32(0); id < undirId; id++ {
u := undirEdges[id][0]
v := undirEdges[id][1]
if visMin[u] && !visMin[v] {
ansMin[id] = '-'
} else if visMin[v] && !visMin[u] {
ansMin[id] = '+'
}
}
out := bufio.NewWriter(os.Stdout)
fmt.Fprintln(out, len(qMax))
fmt.Fprintln(out, string(ansMax))
fmt.Fprintln(out, len(qMin))
fmt.Fprintln(out, string(ansMin))
out.Flush()
}