 # Runtime error(NZEC) on Operations on a Tree

``````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
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())
Initial = list(map(int,input().split()))
Target = list(map(int,input().split()))
Active,Inactive = *(n+1),*(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

@ssjgz , @l_returns , @vijju123 , @aryanc403 , @alei and @karangreat234 anyone please help on this solution. I am stuck over here since 2 days.
Will you please help on calling a counter variable in a recursive function and why this is giving NZEC I am thinking may be because of the counter variable.
Link of submitted solution : https://www.codechef.com/viewsolution/28001391
(Sorry to mention you here)

https://www.codechef.com/viewsolution/28002311
Thank you so much @l_returns 