Please help me find where I'm going wrong! Thank you :) !!

This month’s contest was very tough for me. But I learned a lot :). I solved the 2 easiest problems and Minesweeper :smiley: . But the worst part was finding the logic behind the Fire Escape Routes problem. And not being able to implement it correctly. I started by using ArrayList of HashSets which was not the efficient method.

My ArrayList< HashSet< Integer>> solution. I kept getting TLE :frowning: .

Then I learned about the Disjoint Set Forest data structure. It was easy enough to implement. But I still don’t know where I’m going wrong.

My FIRESC solution using Disjoint Set Forest

I used Java. Please help me. Thank you :slight_smile:

It seems to me, that there is very common mistake, you are multiplying two ints and that can overflow (actually I cannot find small counter example), but you can try to convert prod to long and maybe you will get accepted :wink:

1 Like

Yes. Changing int to long worked. Regretting a lot now. Anyways thanks a lot :)!!