Ques : Problem - 919D - Codeforces

Code: Submission #114628248 - Codeforces

I fail test case number 5. Can someone help me figure out the mistake?

I basically applied dfs to the graph while checking for the cycle, If I find a cycle I simply return true and print -1 or else keep track of the number of occurrences of alphabets, and as soon as we reach the leaf node i.e. graph node with no children, I update the max (ans) value.

Kindly help!