← Home
For problem statement at 2000-2999/2100-2199/2100-2109/2107/problemE.txt this is a correct solution, but verifier at 2000-2999/2100-2199/2100-2109/2107/verifierE.go ends with case 6 (n=5 k=7): expected No (reference unsatisfiable), but got a tree
exit status 1 can you fix the verifier? package main

import (
	"bufio"
	"io"
	"os"
	"strconv"
)

func main() {
	data, _ := io.ReadAll(os.Stdin)
	idx := 0
	nextInt := func() int64 {
		for idx < len(data) && (data[idx] < '0' || data[idx] > '9') {
			idx++
		}
		var v int64
		for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
			v = v*10 + int64(data[idx]-'0')
			idx++
		}
		return v
	}

	t := int(nextInt())
	out := make([]byte, 0, 1<<22)

	for ; t > 0; t-- {
		n := int(nextInt())
		k := nextInt()

		maxW := int64(n) * int64(n-1) * int64(n-2) / 6
		if k > maxW+1 {
			out = append(out, "No\n"...)
			continue
		}

		out = append(out, "Yes\n"...)

		curRoot := 1
		curN := n
		curK := k
		nextLabel := 2

		for curN > 1 {
			if curK == 0 || curN == 2 {
				for i := 0; i < curN-1; i++ {
					out = strconv.AppendInt(out, int64(curRoot), 10)
					out = append(out, ' ')
					out = strconv.AppendInt(out, int64(nextLabel), 10)
					out = append(out, '\n')
					nextLabel++
				}
				break
			}

			maxS := curN - 1
			l, r := 2, maxS
			for l < r {
				m := (l + r + 1) >> 1
				tri := int64(m) * int64(m-1) / 2
				if tri <= curK {
					l = m
				} else {
					r = m - 1
				}
			}
			s := l
			tri := int64(s) * int64(s-1) / 2

			heavy := nextLabel
			nextLabel++

			out = strconv.AppendInt(out, int64(curRoot), 10)
			out = append(out, ' ')
			out = strconv.AppendInt(out, int64(heavy), 10)
			out = append(out, '\n')

			leaves := curN - 1 - s
			for i := 0; i < leaves; i++ {
				out = strconv.AppendInt(out, int64(curRoot), 10)
				out = append(out, ' ')
				out = strconv.AppendInt(out, int64(nextLabel), 10)
				out = append(out, '\n')
				nextLabel++
			}

			curRoot = heavy
			curN = s
			curK -= tri
		}
	}

	w := bufio.NewWriterSize(os.Stdout, 1<<20)
	w.Write(out)
	w.Flush()
}