For problem statement at 0-999/600-699/630-639/638/problemB.txt this is a correct solution, but verifier at 0-999/600-699/630-639/638/verifierB.go ends with case 2 failed: expected mjhadec got cdehamj
exit status 1 can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
)
func main() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
var n int
if _, err := fmt.Fscan(in, &n); err != nil {
return
}
next := make([]int, 26)
prev := make([]int, 26)
for i := 0; i < 26; i++ {
next[i] = -1
prev[i] = -1
}
present := make([]bool, 26)
ok := true
for i := 0; i < n; i++ {
var s string
fmt.Fscan(in, &s)
seen := make([]bool, 26)
for j := 0; j < len(s); j++ {
c := int(s[j] - 'a')
if seen[c] {
ok = false
}
seen[c] = true
present[c] = true
}
for j := 0; j+1 < len(s); j++ {
a := int(s[j] - 'a')
b := int(s[j+1] - 'a')
if next[a] != -1 && next[a] != b {
ok = false
}
if prev[b] != -1 && prev[b] != a {
ok = false
}
next[a] = b
prev[b] = a
}
}
if !ok {
// As per problem statement, input is guaranteed consistent.
// This branch should never be reached.
return
}
visited := make([]bool, 26)
res := make([]byte, 0, 26)
for i := 0; i < 26; i++ {
if present[i] && prev[i] == -1 {
cur := i
for cur != -1 {
if visited[cur] {
ok = false
break
}
visited[cur] = true
res = append(res, byte('a'+cur))
cur = next[cur]
}
if !ok {
return
}
}
}
for i := 0; i < 26; i++ {
if present[i] && !visited[i] {
// Find the head of this component
cur := i
seen := make(map[int]bool)
for prev[cur] != -1 && !seen[cur] {
seen[cur] = true
cur = prev[cur]
}
if prev[cur] != -1 {
// cycle detected; should not happen per guarantees
return
}
for cur != -1 {
if visited[cur] {
break
}
visited[cur] = true
res = append(res, byte('a'+cur))
cur = next[cur]
}
}
}
fmt.Fprintln(out, string(res))
}