Getting TLE in Fire Escape Routes

Problem Link :

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:

Thanks in Advance!!

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

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: