visitor implementation of tarjan