seperated graph segmentation code