For problem statement at 0-999/100-199/190-199/196/problemC.txt this is a correct solution, but verifier at 0-999/100-199/190-199/196/verifierC.go ends with test 2 failed: expected 4 got 1
input:
4
1 2
1 3
3 4
5 13
20 12
16 11
17 14
exit status 1 can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
"sort"
)
type Point struct {
x, y int64
}
func cross(ax, ay, bx, by int64) int64 {
return ax*by - ay*bx
}
func main() {
in := bufio.NewReaderSize(os.Stdin, 1<<20)
out := bufio.NewWriterSize(os.Stdout, 1<<20)
defer out.Flush()
var n int
fmt.Fscan(in, &n)
g := make([][]int, n+1)
for i := 0; i < n-1; i++ {
var u, v int
fmt.Fscan(in, &u, &v)
g[u] = append(g[u], v)
g[v] = append(g[v], u)
}
points := make([]Point, n+1)
for i := 1; i <= n; i++ {
fmt.Fscan(in, &points[i].x, &points[i].y)
}
children := make([][]int, n+1)
sz := make([]int, n+1)
var dfs func(int, int)
dfs = func(v, p int) {
sz[v] = 1
for _, u := range g[v] {
if u == p {
continue
}
children[v] = append(children[v], u)
dfs(u, v)
sz[v] += sz[u]
}
}
dfs(1, 0)
ans := make([]int, n+1)
var solve func(int, []int, int)
solve = func(v int, subset []int, rootPoint int) {
ans[rootPoint] = v
if len(children[v]) == 0 {
return
}
rest := make([]int, 0, len(subset)-1)
for _, id := range subset {
if id != rootPoint {
rest = append(rest, id)
}
}
sort.Slice(rest, func(i, j int) bool {
a := points[rest[i]]
b := points[rest[j]]
r := points[rootPoint]
return cross(a.x-r.x, a.y-r.y, b.x-r.x, b.y-r.y) > 0
})
cur := 0
for _, u := range children[v] {
blockSize := sz[u]
block := rest[cur : cur+blockSize]
solve(u, block, block[0])
cur += blockSize
}
}
rootPoint := 1
for i := 2; i <= n; i++ {
if points[i].x < points[rootPoint].x || (points[i].x == points[rootPoint].x && points[i].y < points[rootPoint].y) {
rootPoint = i
}
}
all := make([]int, n)
for i := 1; i <= n; i++ {
all[i-1] = i
}
solve(1, all, rootPoint)
for i := 1; i <= n; i++ {
if i > 1 {
fmt.Fprint(out, " ")
}
fmt.Fprint(out, ans[i])
}
fmt.Fprintln(out)
}