← Home
For problem statement at 0-999/500-599/560-569/562/problemA.txt this is a correct solution, but verifier at 0-999/500-599/560-569/562/verifierA.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1024*1024), 1024*1024*10)
}

func nextInt() int {
	scanner.Scan()
	res, _ := strconv.Atoi(scanner.Text())
	return res
}

type Edge struct {
	to     int
	length int
}

var w []int
var adj [][]Edge
var deleted []bool
var sz []int

var sumBranch []float64
var totalSum float64
var totalCost float64

func getSizes(u, p int) int {
	sz[u] = 1
	for _, edge := range adj[u] {
		v := edge.to
		if v != p && !deleted[v] {
			sz[u] += getSizes(v, u)
		}
	}
	return sz[u]
}

func getCentroid(u, p, total int) int {
	for _, edge := range adj[u] {
		v := edge.to
		if v != p && !deleted[v] && sz[v] > total/2 {
			return getCentroid(v, u, total)
		}
	}
	return u
}

func dfsOriginal(u, p int, dist int64, branchIdx int) {
	if dist > 0 && w[u] > 0 {
		fd := float64(dist)
		sqrtD := math.Sqrt(fd)
		val := float64(w[u]) * sqrtD
		sumBranch[branchIdx] += val
		totalSum += val
		totalCost += val * fd
	}
	for _, edge := range adj[u] {
		v := edge.to
		if v != p {
			dfsOriginal(v, u, dist+int64(edge.length), branchIdx)
		}
	}
}

func main() {
	if !scanner.Scan() {
		return
	}
	n, _ := strconv.Atoi(scanner.Text())

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

	adj = make([][]Edge, n+1)
	for i := 0; i < n-1; i++ {
		u := nextInt()
		v := nextInt()
		l := nextInt()
		adj[u] = append(adj[u], Edge{to: v, length: l})
		adj[v] = append(adj[v], Edge{to: u, length: l})
	}

	deleted = make([]bool, n+1)
	sz = make([]int, n+1)

	minCost := math.MaxFloat64
	bestNode := -1

	curr := 1
	for {
		totalActive := getSizes(curr, 0)
		C := getCentroid(curr, 0, totalActive)

		sumBranch = make([]float64, len(adj[C]))
		totalSum = 0
		totalCost = 0

		for i, edge := range adj[C] {
			sumBranch[i] = 0
			dfsOriginal(edge.to, C, int64(edge.length), i)
		}

		if totalCost < minCost {
			minCost = totalCost
			bestNode = C
		}

		bestBranch := -1
		for i := range adj[C] {
			if sumBranch[i] > totalSum/2 {
				bestBranch = i
				break
			}
		}

		if bestBranch == -1 {
			break
		}

		nextC := adj[C][bestBranch].to
		if deleted[nextC] {
			break
		}

		deleted[C] = true
		curr = nextC
	}

	fmt.Printf("%d %.10f\n", bestNode, minCost)
}
```