nearly working code but the algo can't go through all the graph. why ?