Getting TLE in Fire Escape Routes

Problem Link : FIRESC Problem - CodeChef

My Logic:For calculating maximum number of escape roots, i am calculating total number of disconnected componenets through DFS and ways of selecting group leader will be product of size of each connected components.

Solution Link: Online Compiler and IDE - GeeksforGeeks

Thanks in Advance!!

I just removed the global definition of ā€œiā€ in your code and it worked:

https://www.codechef.com/viewsolution/33629651

Each recurrence of dfs was changing the same i variable. It should be a local variable of the dfs function. Why not just a local variable of the for loop?

1 Like

Thanks man!

a deadly TLE for sure :cry: