FIRESC getting wrong answer, help

Problem link- Contest Page | CodeChef
Code link- Solution: 49412619 | CodeChef
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.