srm617 div1 500 graph theory, greedy