implement prims algorithm using greedy method