ZOJ Problem Set - 3281
There is a file system whose structure is a tree structure which has only one root. Mr Mouse's home is located in this root. In this file system, he can walk between different directory.
Mr Mouse's life only lasts for n seconds which is very short, so he wants to travel the file system as deep as he can.
In the past, Mr Mouse's ancestors can not travel too deep as they were limited by aps which means they can do only aps times click every second.
However, Mr Mouse has his own aps too. Luckliy, modern file systems support a file named Link.
Besides, Mr Mouse must return back to his home before the end of his life.
NOTES: One directory's Depth means the number of directories Mr Mouse has to pass throught before he arrives at this directory while he doesn't use Link.
There are multiple cases.
For each case output the depth Mr Mouse can travel in his life in one line.
2 3 5 A B B C C D D E E 2 3 5 A B Link:E B C C D D E E
Author: MIN, Zhechen
Source: ZOJ Monthly, December 2009