Traversing the adjacency list
for ( ll y : g [ x ] ) { if ( dist [ y ] > dis + 1 ) { dist [ y ] = dis + 1 ; ways1 [ y ] = ways1 [ x ] ; queue1 . push ( { y , dis + 1 } ) ; } else if ( dist [ y ] == dis + 1 ) { ways1 [ y ] += ways1 [ x ] ; } } }