code for cutting hierarchical tree