Can someone please help on the following code, I am getting NZEC error. The problem link is - TREEEE Problem - CodeChef
def dfs(V,pV,cnt):
if (Initial[V-1]==Target[V-1] and Active[V]==0) or (Initial[V-1]!=Target[V-1] and Active[V]==1):
opr = 0
else:
cnt += 1
opr = 1
for i in adj[V]:
if i==pV:
continue
Active[i] = Inactive[V]
Inactive[i] = (Active[V]+opr)%2
cnt += dfs(i,V,0)
return cnt
n = int(input())
adj = [[] for _ in range(n+1)]
for _ in range(n-1):
s,d = map(int,input().split())
adj[s].append(d)
adj[d].append(s)
Initial = list(map(int,input().split()))
Target = list(map(int,input().split()))
Active,Inactive = [0]*(n+1),[0]*(n+1)
print(dfs(1,0,0))
It is giving correct answer on following TCs :
I/P:
8
1 2
3 1
2 4
5 4
6 3
7 6
1 8
1 0 0 0 0 0 0 1
0 1 0 1 1 1 1 0
O/P
4
I/P
7
1 2
3 1
2 4
5 4
6 3
7 6
1 0 0 0 0 0 0
0 1 0 1 1 1 1
O/P
3
I/P
7
1 2
3 1
2 4
5 2
6 3
3 7
1 0 0 1 0 1 0
0 1 0 1 1 1 1
O/P
4
Please help me on which hidden TestCase it can give NZEC