consider a graph with 5 nodes and edges are
(1,2) (1,3) (2,4) (2,5) and (3,5)
if we are at node 5 neighbors of 5 are 2,3(which are already visited). now if we see else if condition dis[nbr] >=dis[cur] this condition fails for node 3 since dis[nbr] = 1 and dis[cur]=2 but node 3 and 5 have back edge why condition is failing here but code works fine with this condition.Am I missing something?Please correct me.