You are not logged in. Please login at to post your questions!


TWOFL RunTime Error in Java

So when I was trying to do TWOFL question I don't know I was getting RunTimeError for some of the cases and only in subtasks 2 and 3. So I wonder whether this is because of big values. Then somehow in my program I made all value as 1 and traversed it for n=1000 and m=1000. Clearly on my PC I got an error of StackOverFlow. I thought may be my program is going in an infinite recursion so I tried more and couldn't find why is this happening. Then I thought of looking at one of the accepted codes in CPP and changing it into Java. Still it was giving RunTimeError on same cases. Then I looked at others code of Java and many were getting the same error and hence I was sure that this is only with Java who is doing in recursive fashion.

And finally I found this:

I hope this will help you.


This question is marked "community wiki".

asked 14 Jun '18, 17:12

vjvjain0's gravatar image

accept rate: 7%

edited 14 Jun '18, 20:01

@likecs please look over this matter

(14 Jun '18, 20:13) vjvjain04★

only 2 solution in java accepted during the contest it is very much validating your point, but it should't happen in the contest it is like having an edge over java if you are using cpp and we should not be language specific. @vjvjain0 ask the community to look into the matter if you feel it was unfair as i can not do that bcoz i don't have any knowledge of java .


answered 14 Jun '18, 17:57

dk30390's gravatar image

accept rate: 9%

I have dealt with the same problem before.
One way is to increase stack size by creating a new thread for your program. It is same as that mentioned on the cf posts you linked.
Second way is to create your own stack and then do iterative dfs( )
As we know dfs stack size becomes O(n) in worst case. So if n is upto 10^6 its better if you extend stack size before otherwise you may have to deal with stackoverflow error. This bound also depends on what parameters you are passing through dfs calls. Try to reduce them too.


answered 14 Jun '18, 23:49

vbt_95's gravatar image

accept rate: 27%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 14 Jun '18, 17:12

question was seen: 137 times

last updated: 14 Jun '18, 23:49