For problem statement at 0-999/300-399/360-369/362/problemD.txt this is a correct solution, but verifier at 0-999/300-399/360-369/362/verifierD.go ends with build oracle: exit status 1
stat /home/ubuntu/codeforces/0-999/300-399/360-369/362/0-999/300-399/360-369/362/362D.go: directory not found
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"container/heap"
"fmt"
"os"
"strconv"
)
func main() {
reader := bufio.NewReader(os.Stdin)
scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanWords)
nextInt := func() int {
scanner.Scan()
n, _ := strconv.Atoi(scanner.Text())
return n
}
nextInt64 := func() int64 {
scanner.Scan()
n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
return n
}
n := nextInt()
m := nextInt()
p := nextInt()
q := nextInt()
dsu := &DSU{make([]int, n+1), make([]int64, n+1)}
for i := 1; i <= n; i++ {
dsu.parent[i] = i
}
for i := 0; i < m; i++ {
x := nextInt()
y := nextInt()
l := nextInt64()
dsu.union(x, y, l)
}
type compInfo struct {
rep1, rep2 int
}
comps := make(map[int]compInfo)
for i := 1; i <= n; i++ {
root := dsu.find(i)
info := comps[root]
if info.rep1 == 0 {
info.rep1 = i
} else if info.rep2 == 0 {
info.rep2 = i
}
comps[root] = info
}
k := len(comps)
if k < q {
fmt.Println("NO")
return
}
if k-q > p {
fmt.Println("NO")
return
}
needMerge := k - q
remaining := p - needMerge
if remaining > 0 && n == q {
fmt.Println("NO")
return
}
h := &MinHeap{}
heap.Init(h)
for root, info := range comps {
heap.Push(h, Component{
sum: dsu.sum[root],
rep1: info.rep1,
rep2: info.rep2,
})
}
ans := make([][2]int, 0, p)
for i := 0; i < needMerge; i++ {
c1 := heap.Pop(h).(Component)
c2 := heap.Pop(h).(Component)
cost := c1.sum + c2.sum + 1
if cost > 1000000000 {
cost = 1000000000
}
ans = append(ans, [2]int{c1.rep1, c2.rep1})
newComp := Component{
sum: c1.sum + c2.sum + cost,
rep1: c1.rep1,
}
if c1.rep2 != 0 {
newComp.rep2 = c1.rep2
} else if c2.rep2 != 0 {
newComp.rep2 = c2.rep2
} else {
newComp.rep2 = c2.rep1
}
heap.Push(h, newComp)
}
if remaining > 0 {
var target *Component
for h.Len() > 0 {
c := heap.Pop(h).(Component)
if target == nil && c.rep2 != 0 {
target = &c
}
}
if target == nil {
fmt.Println("NO")
return
}
for i := 0; i < remaining; i++ {
ans = append(ans, [2]int{target.rep1, target.rep2})
}
}
fmt.Println("YES")
for _, road := range ans {
fmt.Printf("%d %d\n", road[0], road[1])
}
}
type DSU struct {
parent []int
sum []int64
}
func (d *DSU) find(x int) int {
if d.parent[x] != x {
d.parent[x] = d.find(d.parent[x])
}
return d.parent[x]
}
func (d *DSU) union(x, y int, l int64) {
rootX := d.find(x)
rootY := d.find(y)
if rootX == rootY {
d.sum[rootX] += l
return
}
d.parent[rootX] = rootY
d.sum[rootY] += d.sum[rootX] + l
}
type Component struct {
sum int64
rep1 int
rep2 int
}
type MinHeap []Component
func (h MinHeap) Len() int { return len(h) }
func (h MinHeap) Less(i, j int) bool { return h[i].sum < h[j].sum }
func (h MinHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *MinHeap) Push(x interface{}) { *h = append(*h, x.(Component)) }
func (h *MinHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[0 : n-1]
return x
}
```