Traverse the adjacency list
for y in g [ x ] : NEW_LINE INDENT if ( dist1 [ y ] > dis + 1 ) : NEW_LINE INDENT dist1 [ y ] = dis + 1 NEW_LINE ways2 [ y ] = ways2 [ x ] NEW_LINE queue2 . append ( [ y , dis + 1 ] ) NEW_LINE DEDENT elif ( dist1 [ y ] == 1 + dis ) : NEW_LINE INDENT ways2 [ y ] += ways2 [ x ] NEW_LINE DEDENT DEDENT