implement greedy contruct tree from graph