For problem statement at 1000-1999/1900-1999/1900-1909/1907/problemG.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1900-1909/1907/verifierG.go ends with mismatch
expected:
-1
-1
-1
-1
1
2
1
3
-1
0
-1
-1
1
3
4
5 3 2 4
-1
1
2
-1
1
2
-1
1
1
2
6 2
-1
2
3 2
-1
-1
3
5 4 3
1
1
1
2
-1
0
-1
0
3
5 1 4
-1
2
2 3
1
2
-1
2
2 5
-1
1
2
1
4
1
1
1
1
1
3
3
6 1 3
3
2 5 4
3
3 2 4
1
2
-1
-1
-1
3
5 6 4
2
1 3
1
3
-1
2
3 2
0
0
-1
2
2 1
-1
1
4
1
1
-1
-1
0
2
3 2
-1
1
2
3
5 2 6
0
2
4 3
-1
-1
1
3
-1
-1
-1
-1
-1
1
2
2
3 4
-1
1
2
-1
2
3 1
-1
-1
-1
1
3
1
4
-1
-1
-1
1
2
-1
1
3
1
2
-1
-1
-1
2
1 3
actual:
-1
-1
-1
-1
1
2
1
3
-1
0
-1
-1
1
3
4
2 3 5 4
-1
1
2
-1
1
2
-1
1
1
2
6 2
-1
2
3 2
-1
-1
3
4 5 3
1
1
1
2
-1
0
-1
0
3
5 1 4
-1
2
2 3
1
2
-1
2
2 5
-1
1
2
1
4
1
1
1
1
1
3
3
1 6 3
3
2 5 4
3
2 3 4
1
2
-1
-1
-1
3
5 6 4
2
1 3
1
3
-1
2
3 2
0
0
-1
2
1 2
-1
1
4
1
1
-1
-1
0
2
3 2
-1
1
2
3
2 5 6
0
2
4 3
-1
-1
1
3
-1
-1
-1
-1
-1
1
2
2
3 4
-1
1
2
-1
2
4 2
-1
-1
-1
1
3
1
4
-1
-1
-1
1
2
-1
1
3
1
2
-1
-1
-1
2
1 3
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"io"
"os"
)
type FastScanner struct {
data []byte
idx int
}
func NewFastScanner() *FastScanner {
data, _ := io.ReadAll(os.Stdin)
return &FastScanner{data: data}
}
func (fs *FastScanner) skip() {
for fs.idx < len(fs.data) && fs.data[fs.idx] <= ' ' {
fs.idx++
}
}
func (fs *FastScanner) NextInt() int {
fs.skip()
sign := 1
if fs.data[fs.idx] == '-' {
sign = -1
fs.idx++
}
val := 0
for fs.idx < len(fs.data) {
c := fs.data[fs.idx]
if c < '0' || c > '9' {
break
}
val = val*10 + int(c-'0')
fs.idx++
}
return val * sign
}
func (fs *FastScanner) NextString() string {
fs.skip()
start := fs.idx
for fs.idx < len(fs.data) && fs.data[fs.idx] > ' ' {
fs.idx++
}
return string(fs.data[start:fs.idx])
}
func writeInt(w *bufio.Writer, x int) {
if x == 0 {
w.WriteByte('0')
return
}
if x < 0 {
w.WriteByte('-')
x = -x
}
var buf [20]byte
i := len(buf)
for x > 0 {
i--
buf[i] = byte('0' + x%10)
x /= 10
}
w.Write(buf[i:])
}
func main() {
fs := NewFastScanner()
out := bufio.NewWriterSize(os.Stdout, 1<<20)
defer out.Flush()
t := fs.NextInt()
for ; t > 0; t-- {
n := fs.NextInt()
s := fs.NextString()
a := make([]int, n)
indeg := make([]int, n)
for i := 0; i < n; i++ {
a[i] = fs.NextInt() - 1
indeg[a[i]]++
}
b := make([]byte, n)
for i := 0; i < n; i++ {
b[i] = s[i] - '0'
}
queue := make([]int, n)
head, tail := 0, 0
for i := 0; i < n; i++ {
if indeg[i] == 0 {
queue[tail] = i
tail++
}
}
ans := make([]int, 0, n)
for head < tail {
v := queue[head]
head++
x := b[v]
if x == 1 {
ans = append(ans, v+1)
}
p := a[v]
b[p] ^= x
indeg[p]--
if indeg[p] == 0 {
queue[tail] = p
tail++
}
}
vis := make([]bool, n)
ok := true
for i := 0; i < n && ok; i++ {
if indeg[i] > 0 && !vis[i] {
cycle := make([]int, 0)
cur := i
for {
vis[cur] = true
cycle = append(cycle, cur)
cur = a[cur]
if cur == i {
break
}
}
m := len(cycle)
assign := make([]byte, m)
ones := 0
for j := 1; j < m; j++ {
assign[j] = assign[j-1] ^ b[cycle[j]]
if assign[j] == 1 {
ones++
}
}
if assign[m-1]^assign[0] != b[cycle[0]] {
ok = false
break
}
if ones <= m-ones {
for j := 0; j < m; j++ {
if assign[j] == 1 {
ans = append(ans, cycle[j]+1)
}
}
} else {
for j := 0; j < m; j++ {
if assign[j] == 0 {
ans = append(ans, cycle[j]+1)
}
}
}
}
}
if !ok {
writeInt(out, -1)
out.WriteByte('\n')
} else {
writeInt(out, len(ans))
out.WriteByte('\n')
for i, v := range ans {
if i > 0 {
out.WriteByte(' ')
}
writeInt(out, v)
}
out.WriteByte('\n')
}
}
}
```