Implemented basic tree traversal algorithm using recursion

This is not accepted as an answer on Codeforce yet. There are timeout
errors.