Traversing the adjacency list
for y in g [ x ] : NEW_LINE INDENT if ( dist [ y ] > dis + 1 ) : NEW_LINE INDENT dist [ y ] = dis + 1 NEW_LINE ways1 [ y ] = ways1 [ x ] NEW_LINE queue1 . append ( [ y , dis + 1 ] ) NEW_LINE DEDENT elif ( dist [ y ] == dis + 1 ) : NEW_LINE INDENT ways1 [ y ] += ways1 [ x ] NEW_LINE DEDENT DEDENT