Getting ans in wrong sequence

please check my code i am not getting my ans in correct sequence, and i am unable to find the mistake

You just have to comment line 22 I guess.
Right now you graph is not directed .