For problem statement at 0-999/500-599/510-519/510/problemC.txt this is a correct solution, but verifier at 0-999/500-599/510-519/510/verifierC.go ends with 002.in: expected
zyxwvusrqtponmlkjihgfedcba
but got
abcdefghiklmnopqrsuvwxyztj
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
// Use buffered I/O for speed, though N is small (100)
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
// Read number of names
if !scanner.Scan() {
return
}
var n int
fmt.Sscanf(scanner.Text(), "%d", &n)
// Read names into a slice
names := make([]string, n)
for i := 0; i < n; i++ {
scanner.Scan()
names[i] = scanner.Text()
}
// Adjacency list for the graph (26 lowercase letters)
// adj[u] contains list of v such that u must come before v
adj := make([][]int, 26)
inDegree := make([]int, 26)
// Compare adjacent names to build the dependency graph
for i := 0; i < n-1; i++ {
s1 := names[i]
s2 := names[i+1]
len1 := len(s1)
len2 := len(s2)
minLen := len1
if len2 < len1 {
minLen = len2
}
diffFound := false
for j := 0; j < minLen; j++ {
if s1[j] != s2[j] {
u := int(s1[j] - 'a')
v := int(s2[j] - 'a')
// Add edge u -> v
adj[u] = append(adj[u], v)
inDegree[v]++
diffFound = true
break
}
}
// If no difference is found, s1 must be a prefix of s2 (or equal).
// If s1 is longer than s2 and no difference found, s1 cannot precede s2 lexicographically.
if !diffFound && len1 > len2 {
fmt.Println("Impossible")
return
}
}
// Topological Sort using Kahn's Algorithm
queue := make([]int, 0, 26)
for i := 0; i < 26; i++ {
if inDegree[i] == 0 {
queue = append(queue, i)
}
}
result := make([]byte, 0, 26)
for len(queue) > 0 {
u := queue[0]
queue = queue[1:]
result = append(result, byte(u+'a'))
for _, v := range adj[u] {
inDegree[v]--
if inDegree[v] == 0 {
queue = append(queue, v)
}
}
}
// If result does not contain all 26 letters, there is a cycle
if len(result) < 26 {
fmt.Println("Impossible")
} else {
fmt.Println(string(result))
}
}
```