← Home
For problem statement at 0-999/100-199/130-139/131/problemD.txt this is a correct solution, but verifier at 0-999/100-199/130-139/131/verifierD.go ends with All tests passed can you fix the verifier? ```go
package main

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

func main() {
	// Use buffered I/O for speed
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscan(reader, &n)

	// Adjacency list for the graph
	adj := make([][]int, n+1)
	// Array to track the degree of each node
	degree := make([]int, n+1)

	// Read n edges
	for i := 0; i < n; i++ {
		var u, v int
		fmt.Fscan(reader, &u, &v)
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
		degree[u]++
		degree[v]++
	}

	// Initialize queue with leaf nodes (degree 1)
	// These are nodes definitely not on the cycle (tails/trees attached to the ringroad)
	leaves := make([]int, 0, n)
	for i := 1; i <= n; i++ {
		if degree[i] == 1 {
			leaves = append(leaves, i)
		}
	}

	// Array to mark if a node is on the cycle (ringroad)
	// Initially assume all are on cycle, then mark false as we peel the leaves
	onCycle := make([]bool, n+1)
	for i := 1; i <= n; i++ {
		onCycle[i] = true
	}

	// Process the queue: topological sort logic to remove trees
	head := 0
	for head < len(leaves) {
		u := leaves[head]
		head++
		onCycle[u] = false

		for _, v := range adj[u] {
			degree[v]--
			if degree[v] == 1 {
				leaves = append(leaves, v)
			}
		}
	}

	// Prepare for BFS to calculate distances from the ringroad
	dist := make([]int, n+1)
	bfsQueue := make([]int, 0, n)

	for i := 1; i <= n; i++ {
		if onCycle[i] {
			dist[i] = 0
			bfsQueue = append(bfsQueue, i)
		} else {
			dist[i] = -1 // Mark as unvisited
		}
	}

	// Multi-source BFS starting from all cycle nodes
	head = 0
	for head < len(bfsQueue) {
		u := bfsQueue[head]
		head++

		for _, v := range adj[u] {
			if dist[v] == -1 {
				dist[v] = dist[u] + 1
				bfsQueue = append(bfsQueue, v)
			}
		}
	}

	// Output the results
	for i := 1; i <= n; i++ {
		if i > 1 {
			fmt.Fprint(writer, " ")
		}
		fmt.Fprint(writer, dist[i])
	}
	fmt.Fprintln(writer)
}
```