For problem statement at 1000-1999/1400-1499/1460-1469/1468/problemM.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1460-1469/1468/verifierM.go ends with wrong answer on case 6
input:
1
4
4 6 7 10 6
1 6
1 10
2 2 1
expected:
1 1
got:
2 1
exit status 1 can you fix the verifier? package main
import (
"bufio"
"fmt"
"math"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var t int
fmt.Fscan(reader, &t)
for tc := 0; tc < t; tc++ {
var n int
fmt.Fscan(reader, &n)
sets := make([][]int, n)
total := 0
for i := 0; i < n; i++ {
var k int
fmt.Fscan(reader, &k)
sets[i] = make([]int, k)
for j := 0; j < k; j++ {
fmt.Fscan(reader, &sets[i][j])
}
total += k
}
B := int(math.Sqrt(float64(total))) + 1
large := []int{}
small := []int{}
for i := 0; i < n; i++ {
if len(sets[i]) >= B {
large = append(large, i)
} else {
small = append(small, i)
}
}
found := false
a, b := -1, -1
for i := 0; i < len(large) && !found; i++ {
m := make(map[int]bool)
for _, x := range sets[large[i]] {
m[x] = true
}
for j := i + 1; j < len(large) && !found; j++ {
c := 0
for _, x := range sets[large[j]] {
if m[x] {
c++
if c >= 2 {
found = true
a, b = large[i]+1, large[j]+1
break
}
}
}
}
}
if !found && len(large) > 0 {
e2l := make(map[int][]int)
for _, idx := range large {
for _, x := range sets[idx] {
e2l[x] = append(e2l[x], idx)
}
}
for _, i := range small {
if found {
break
}
cnt := make(map[int]int)
for _, x := range sets[i] {
for _, j := range e2l[x] {
cnt[j]++
if cnt[j] >= 2 {
found = true
a, b = i+1, j+1
break
}
}
if found {
break
}
}
}
}
if !found {
p2s := make(map[[2]int]int)
for _, i := range small {
if found {
break
}
for j := 0; j < len(sets[i]) && !found; j++ {
for k := j + 1; k < len(sets[i]) && !found; k++ {
x, y := sets[i][j], sets[i][k]
if x > y {
x, y = y, x
}
p := [2]int{x, y}
if s, ok := p2s[p]; ok {
found = true
a, b = s+1, i+1
break
}
p2s[p] = i
}
}
}
}
if found {
fmt.Fprintln(writer, a, b)
} else {
fmt.Fprintln(writer, -1)
}
}
}