← Home
For problem statement at 1000-1999/1300-1399/1370-1379/1375/problemG.txt this is a correct solution, but verifier at 1000-1999/1300-1399/1370-1379/1375/verifierG.go ends with All 98 tests passed can you fix the verifier? package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	if _, err := fmt.Fscan(reader, &n); err != nil {
		return
	}

	adj := make([][]int, n+1)
	for i := 0; i < n-1; i++ {
		var u, v int
		fmt.Fscan(reader, &u, &v)
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	color := make([]int, n+1)
	for i := 1; i <= n; i++ {
		color[i] = -1
	}

	queue := make([]int, 0, n)
	queue = append(queue, 1)
	color[1] = 0

	counts := [2]int{1, 0}

	for len(queue) > 0 {
		u := queue[0]
		queue = queue[1:]

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

	ans := counts[0]
	if counts[1] < ans {
		ans = counts[1]
	}

	fmt.Println(ans - 1)
}