Блог пользователя TheNoOneCoder

Автор TheNoOneCoder, история, 3 года назад, По-английски

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])

Полный текст и комментарии »

  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится

Автор TheNoOneCoder, история, 4 года назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится