Hi everybody!

I'm trying to solve this **usaco GOLD** problem. I've tryed somehow to think and solve it with suffix automata but i couldn't. Now trying to read solution but can't get it. I don't understand about which graph talking there. Also, it uses trie and i have never written trie before.

Does anyone have any idea to solve this problem using suffix automata? Or if it's impossible with suffix automata can anyone share their ideas about this problem ?

Bruh, in such situations, if I were you, I would want to learn about trie. (Btw trie is very easy to learn). ;)