For problem statement at 1000-1999/1200-1299/1280-1289/1286/problemB.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1280-1289/1286/verifierB.go ends with All tests passed can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscan(reader, &n)
parent := make([]int, n+1)
c := make([]int, n+1)
children := make([][]int, n+1)
root := -1
for i := 1; i <= n; i++ {
fmt.Fscan(reader, &parent[i], &c[i])
if parent[i] == 0 {
root = i
} else {
children[parent[i]] = append(children[parent[i]], i)
}
}
// Compute subtree sizes
subtreeSize := make([]int, n+1)
// Topological order via BFS
order := make([]int, 0, n)
queue := []int{root}
for len(queue) > 0 {
v := queue[0]
queue = queue[1:]
order = append(order, v)
for _, ch := range children[v] {
queue = append(queue, ch)
}
}
// Process in reverse order to compute subtree sizes
for i := len(order) - 1; i >= 0; i-- {
v := order[i]
subtreeSize[v] = 1
for _, ch := range children[v] {
subtreeSize[v] += subtreeSize[ch]
}
}
// For each vertex, we need to assign a rank within its subtree.
// c[i] = number of vertices j in subtree of i with a[j] < a[i]
// This means a[i] should be the (c[i]+1)-th smallest in its subtree.
// We process from the root down. For each vertex, we have a list of
// available "slots" (sorted positions). The vertex picks slot c[i] (0-indexed),
// then the remaining slots are distributed to children's subtrees.
// Each vertex gets a list of available values. We process DFS.
// The root gets values [1..n].
ans := make([]int, n+1)
valid := true
// We'll use a slice-based approach. Each vertex receives a sorted slice of available values.
// It picks the c[i]-th one, removes it, then distributes the rest to children subtrees
// in order of how we split them.
type frame struct {
v int
values []int
}
stack := []frame{{root, nil}}
// Initialize root values
rootVals := make([]int, n)
for i := 0; i < n; i++ {
rootVals[i] = i + 1
}
stack[0].values = rootVals
for len(stack) > 0 && valid {
top := stack[len(stack)-1]
stack = stack[:len(stack)-1]
v := top.v
vals := top.values
if len(vals) != subtreeSize[v] {
valid = false
break
}
if c[v] >= len(vals) {
valid = false
break
}
// Pick the c[v]-th value (0-indexed)
ans[v] = vals[c[v]]
// Remove that element
remaining := make([]int, 0, len(vals)-1)
remaining = append(remaining, vals[:c[v]]...)
remaining = append(remaining, vals[c[v]+1:]...)
// Distribute remaining to children subtrees
// The remaining is still sorted. We assign first subtreeSize[ch1] to child1, etc.
idx := 0
for _, ch := range children[v] {
sz := subtreeSize[ch]
if idx+sz > len(remaining) {
valid = false
break
}
childVals := remaining[idx : idx+sz]
idx += sz
stack = append(stack, frame{ch, childVals})
}
if idx != len(remaining) {
valid = false
}
}
if !valid {
fmt.Fprintln(writer, "NO")
return
}
fmt.Fprintln(writer, "YES")
for i := 1; i <= n; i++ {
if i > 1 {
fmt.Fprint(writer, " ")
}
fmt.Fprint(writer, ans[i])
}
fmt.Fprintln(writer)
}
```