Google interview question

basically code prims algorithm