TheNoOneCoder's blog

By TheNoOneCoder, history, 4 years ago, In English

I was doing this problem 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])

Full text and comments »

  • Vote: I like it
  • +15
  • Vote: I do not like it

By TheNoOneCoder, history, 4 years ago, In English

Hello Everyone. I just want to ask about your codeforces journey , when you got to know about codeforces, how you practiced and how codeforces helped you? Thanks

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it