In the problem Restoring trees(set 2 problem 1) I am getting SIGSEGV runtime error in 4 test cases out of 41 test cases and getting 88/100. As contest has ended can somebody help me.I have tried it for many hours but still not getting 100.
HackerEarth has very less stack(implicit) size for Java and probably for Python too.
I checked it a few days back its almost only 2e4 for Java and I have heard Python users have faced similar problem in past.
I am using recursion and code is of O(n) complexity.
import sys
sys.setrecursionlimit(2000000000)
def trav(st,end,par):
global s,ss
ind=st+1
while ind<end:
node=s[ind]
del s[ind]
ss[node[0]]=par+1
if node[1]-ind==1:
ind=node[1]
continue
else:
trav(ind,node[1],node[0])
ind=node[1]
n=int(sys.stdin.readline())
st=list(map(int,sys.stdin.readline().split()))
end=list(map(int,sys.stdin.readline().split()))
co=0
s={}
for i,j in zip(st,end):
if i==0 and j==n:
root=co
s[i]=[co,j]
co+=1
del st,end
ss={root:0}
trav(0,n,root)
for i in range(n):
print(ss[i],end=" ")
print()
My approach is right as I am getting no WA but RE(SIGSEGV) on 4 test cases.Like most take test cases took more than 1 second to solve but these with RE stop before 0.5 second only. Can you tell why SIGSEGV occurs and why is it occuring in my case
hello, I’m able to solve this with full 100pts…Yes, there is some error in the test cases I don’t know because when I submit the code in c++14 then it got AC and when I submit the same code with python3, Java8, C it got RE in 2-3 test cases…
BTW the question was quite easy …One simple recursive dfs will able to give to AC in just O(N) time complexity…