srm571 div1 500 graph theory, search