Tarjan's algorithm