FIRESC - Editorial

can anybody tell why is my code failing?
https://www.codechef.com/viewsolution/29309499
Thanks in advance

Could anyone please help me spot any errors with my code?

https://www.codechef.com/viewsolution/29352747

My approach is same. I have used both dfs and bfs but I got WA. Finally I used BFS to avoid stack overflow. Please look into my code to detect the error.

https://www.codechef.com/viewsolution/31898752

@anton_lunyov : thank you so much :slight_smile:

I used path by compression in python, but I am getting Runtime error.
Please can anyone points out the error.
https://www.codechef.com/viewsolution/36126530
Thanks a lot

Have a look at it, by disjoint union set solution.

can some one provide me test cases

#routes={}
#elements=[]
#graph={}
#visited={}
def dfs(u,m):
visited[u]=True
#print(m,u)
routes[m]=routes[m]+1
for i in graph[u]:
if visited[i]!=True:
dfs(i,m)
M = 1000000007
for _ in range(0,int(input())):
routes={}
elements=[]
graph={}
visited={}
n,m=map(int,input().split())
for i in range(1,n+1):
elements.append(i)
routes[i]=0
graph[i]=[]
visited[i]=False
for _ in range(0,m):
i,j=map(int,input().split())
graph[i].append(j)
graph[j].append(i)
for i in elements:
if visited[i]==False:
dfs(i,i)
# print(routes[i])
cum_pro=1
co=0
for i in routes.keys():
if routes[i]!=0:
#print(i)
co=co+1
cum_pro=(cum_pro*routes[i])%M

 print(str(co)+" "+str(cum_pro))

iam getting NZEC can someone provide me the reason

getting WA https://www.codechef.com/viewsolution/44998929