# Hackerearth May circuit 2019

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.

https://www.hackerearth.com/submission/26712119/

1 Like

@samarthtandon
is the right person to be asked.

2 Likes

Will have to write a code first to unlock it

1 Like

should I copy my code over here??It is in python

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.

but some(very few) have got 100 in this problem in python

Can you share one recursive dfs-based python solution ?

Most of them are iterative dfs.

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]

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â€¦

you can check my solution hereâ€¦

Well I mentioned the reason -

Its because of stack Overflow Error.

I think this contest is quite good for me â€¦Iâ€™m able to solve all 8 questions this time (only 1 question with 52pts)

but the explanation of problem statements was terrible this timeâ€¦every question have some amount of ambiguity in the statementsâ€¦

1 Like

There is no error in test cases.

yes, but I donâ€™t know why it fails on other programming language other than c++14

even in C language it was failed and got REâ€¦(donâ€™t know the reason till now!!)

I donâ€™t know about C but for Java and Python, Iâ€™m preety sure.

1 Like

I think you can Unlock any problem without solving itâ€¦but it will cost to detect all your marks from that question

here is my recursive python 3 codeâ€¦but RE in 5 test cases:

https://www.hackerearth.com/submission/26719436/

Yup, this is what I mean to say. Try with iterative DFS and it will run fine with all AC.

2 Likes

but I donâ€™t think Iterative solution to the problem of this type was good practiceâ€¦

I think HackerEarth need to resolve this problemâ€¦

BTW thanksâ€¦I never expect these type of errorsâ€¦

Ikrâ€¦ I would rather solve it before unlockingâ€¦ will get back here if I get any other reason for runtime error