Problem Link: https://www.codechef.com/problems/FIRESC

Below is my code can anyone tell me what is wrong with my code, It is giving TLE even I implemented the iterative approach of DFS, even the recursive approaches passes all the test case.

Thanks in Advance

@waqar_ahmad224 @ssjgz @ssrivastava990 @aneee004 @hello_hell @galencolin

```
from sys import stdin
mod=10*9 +7
def inp():
return int(stdin.readline())
def mp():
return map(int,stdin.readline().split())
def DFS(d,ver,visited,ans):
visited.add(ver)
c=1
stack=[ver]
while stack:
flag=0
for i in d[stack[-1]]:
if i not in visited:
flag=1
visited.add(i)
stack.append(i)
c+=1
break
if not flag:
stack.pop()
ans=(ans%mod * c%mod)%mod
return ans
def solve():
n,m=mp()
d={i:set() for i in range(1,n+1)}
for i in range(m):
a,b=mp()
d[a].add(b)
d[b].add(a)
c,ans=0,1
visited=set()
for i in range(1,n+1):
if i not in visited:
c+=1
ans=DFS(d,i,visited,ans)
print(c,ans)
for _ in range(inp()):
solve()
```