### My issue

Giving RTE at

possibility=dfs(child,node,graph,tower,m)

[Previous line repeated 995 more times]

File “/mnt/sol.py”, line 12, in dfs

if child!=parent:

RecursionError: maximum recursion depth exceeded in comparison

### My code

```
# cook your dish here
def ncr(n,r):
s=1
for i in range(1, r+1):
s=s*(n - r + i) / i
return int(s)
def dfs(node,parent,graph,tower,m):
length=tower[node]
ways=1
for child in graph[node]:
if child!=parent:
possibility=dfs(child,node,graph,tower,m)
ways=(((ways*ncr(length+possibility[0],length)%m)*possibility[1])%m)
length+=possibility[0]
if length>0:
length+=1
return (length,ways)
for _ in range(int(input())):
nodes=int(input())
towers=list(map(int,input().split()))
adj=[[] for _ in range(nodes)]
for _ in range(nodes-1):
x,y=map(int,input().split())
adj[x-1].append(y-1)
adj[y-1].append(x-1)
print(dfs(0,-1,adj,towers,10**9+7)[1])
```

Problem Link: BUILDT Problem - CodeChef