For problem statement at 1000-1999/1300-1399/1320-1329/1322/problemC.txt this is a correct solution, but verifier at 1000-1999/1300-1399/1320-1329/1322/verifierC.go ends with All 100 tests passed can you fix the verifier? package main
import (
"os"
"strconv"
)
var buffer = make([]byte, 1<<20)
var bpos, bmax int
func readChar() byte {
if bpos >= bmax {
bmax, _ = os.Stdin.Read(buffer)
bpos = 0
if bmax == 0 {
return 0
}
}
res := buffer[bpos]
bpos++
return res
}
func readInt() int {
c := readChar()
for c <= ' ' && c != 0 {
c = readChar()
}
if c == 0 {
return 0
}
res := 0
for c > ' ' {
res = res*10 + int(c-'0')
c = readChar()
}
return res
}
func readInt64() int64 {
c := readChar()
for c <= ' ' && c != 0 {
c = readChar()
}
if c == 0 {
return 0
}
res := int64(0)
for c > ' ' {
res = res*10 + int64(c-'0')
c = readChar()
}
return res
}
type Hash struct {
h1, h2 uint64
}
func splitmix64(x *uint64) uint64 {
*x += 0x9e3779b97f4a7c15
z := *x
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9
z = (z ^ (z >> 27)) * 0x94d049bb133111eb
return z ^ (z >> 31)
}
func gcd(a, b int64) int64 {
for b != 0 {
a, b = b, a%b
}
return a
}
var outBuf []byte
func printInt64(x int64) {
outBuf = strconv.AppendInt(outBuf, x, 10)
outBuf = append(outBuf, '\n')
if len(outBuf) >= 1<<16 {
os.Stdout.Write(outBuf)
outBuf = outBuf[:0]
}
}
func main() {
t := readInt()
if t == 0 {
return
}
var seed uint64 = 123456789
c := make([]int64, 0, 500005)
leftHash := make([]Hash, 0, 500005)
rightHash := make([]Hash, 0, 500005)
for i := 0; i < t; i++ {
n := readInt()
m := readInt()
if cap(c) < n+1 {
c = make([]int64, n+1)
leftHash = make([]Hash, n+1)
rightHash = make([]Hash, n+1)
} else {
c = c[:n+1]
leftHash = leftHash[:n+1]
rightHash = rightHash[:n+1]
}
for j := 1; j <= n; j++ {
c[j] = readInt64()
}
for j := 1; j <= n; j++ {
leftHash[j] = Hash{splitmix64(&seed), splitmix64(&seed)}
rightHash[j] = Hash{0, 0}
}
for j := 0; j < m; j++ {
u := readInt()
v := readInt()
rightHash[v].h1 ^= leftHash[u].h1
rightHash[v].h2 ^= leftHash[u].h2
}
sums := make(map[Hash]int64)
for j := 1; j <= n; j++ {
if rightHash[j].h1 != 0 || rightHash[j].h2 != 0 {
sums[rightHash[j]] += c[j]
}
}
ans := int64(0)
for _, sum := range sums {
ans = gcd(ans, sum)
}
printInt64(ans)
}
if len(outBuf) > 0 {
os.Stdout.Write(outBuf)
}
}