FIRESC getting wrong answer, help

Problem link- CodeChef: Practical coding for everyone
Code link- CodeChef: Practical coding for everyone
example cases are running successfully, don’t know why it is giving wrong answer
please help
Used logic- used dfs algorithm to count the components of graph which is the number of fire exit, next multiplied number of nodes of each components to find out the number of ways to choose captains.