You are not logged in. Please login at www.codechef.com 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:
http://codeforces.com/blog/entry/21472
http://codeforces.com/blog/entry/166

I hope this will help you.

Thanks

This question is marked "community wiki".

asked 14 Jun, 17:12

vjvjain0's gravatar image

4★vjvjain0
918
accept rate: 7%

edited 14 Jun, 20:01

@likecs please look over this matter

(14 Jun, 20:13) vjvjain04★

https://www.codechef.com/viewsolution/18848381

https://www.codechef.com/viewsolution/18778145

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 .

link

answered 14 Jun, 17:57

dk30390's gravatar image

4★dk30390
744
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( https://www.geeksforgeeks.org/iterative-depth-first-traversal/ )
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.

link

answered 14 Jun, 23:49

vbt_95's gravatar image

4★vbt_95
4406
accept rate: 27%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×1,244
×1,218
×347
×317
×179

question asked: 14 Jun, 17:12

question was seen: 125 times

last updated: 14 Jun, 23:49