Python :- Exit code is -1073741571

Revision en1, by TheNoOneCoder, 2021-06-05 19:34:49

I was doing this problem[problem:1006E] in python. I am receiving Runtime error on test 3 with exit code -1073741571. I am not able to understand the fault in my code. Any help is greatly appreciated.

Link to my submission .

The main part of the code is below:


cnt = 1 d = defaultdict(lambda:0) travesal = [] subtreesize = defaultdict(lambda:0) def dfs(node,parent): global adj,cnt travesal.append(node) ans = 1 for child in adj[node]: if child==parent: continue d[child]=cnt cnt+=1 ans+=dfs(child,node) subtreesize[node]=ans return ans n,q = li() p = li() adj = [[] for i in range(200002)] for i in range(len(p)): adj[i+1].append(p[i]-1) # print(p[i]-1) adj[p[i]-1].append(i+1) dfs(0,-1) for i in range(len(travesal)): travesal[i]+=1 for i in range(q): u,k = li() u-=1 dis = d[u] x = dis+k-1 # print("x",x) if x>=len(travesal) or subtreesize[u]<k: print(-1) else: print(travesal[x])
Tags #python, #pypy3, #runtime, *1600, #help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English TheNoOneCoder 2021-06-05 19:40:32 47
en1 English TheNoOneCoder 2021-06-05 19:34:49 1177 Initial revision (published)