graph pruning and tarjan's