Getting TLE after doing a BFS and implementing a trie on H1

Problem : H1 Problem - CodeChef

This is my implementation
http://www.codechef.com/viewplaintext/2707780

I am implementing a BFS to check all reachable states and mapping the states reached in a trie.
But I am unable to get it to run within the time limits. I will be grateful if someone can throw some light on how to improve my code.

here is my code in pastebin for better readability