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

Автор ttrkaya, история, 9 лет назад, По-английски

I have just solved this great problem: http://codeforces.com/problemset/problem/429/A

I have solved the problem by using DFS on the given tree, like most others did, and like the editorial suggests.

As I was coding the solution, I was sure that I would get a stack-overflow, and then I would reimplement the solution using BFS. But I did not..

In the problem, it is very possible that the tree is a path (a unary tree where each node has at most one child), and its depth could be 10^5. In fact the test case #2 is a path.

A stack of depth 10^5 should be an overflow right? I have not used any linker settings to increase the stack size.

So what I'm wondering is: is it just a missing test case? Or does codeforces compilers do something special so that we don`t get a stack overflow even at depth 10^5?

I`m wondering this, because lots of times, it is easier to code the recursive DFS solution than iterative BFS solution. If possible I wish not to care about the stack-overflows.

Thank you in advance.

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

»
9 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Default stack size in codeforces is 256MB

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    That explains it. Thank you very much :)

    So a typical codeforces problem will have the memory limit of 256MB. It is heap memory right? So in total we have 256MB heap + 256MB stack = 512 MB memory?

»
9 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

this post by MikeMirzayanov says that the g++ compile option is g++.exe -static -DONLINE_JUDGE -lm -s -x c++ -Wl,--stack=268435456 -O2 -o {filename}.exe {file} in that,-Wl,--stack=268435456 says that the stack size is 268435456 bytes(=256MB) which is far more than what your program will use. (In worse case, your program will use 100000*3*4=1200000 bytes)