Getting TLE in Treegame question from August Cook Off

Can any one help me in finding why my code is getting TLE for the TREEGAME problem. Link for the code is

I have used BFS and Adjacency matrix representation for the graph.