Traverse the adjacency list
for ( ll y : g [ x ] ) { if ( dist1 [ y ] > dis + 1 ) { dist1 [ y ] = dis + 1 ; ways2 [ y ] = ways2 [ x ] ; queue2 . push ( { y , dis + 1 } ) ; } else if ( dist1 [ y ] == 1 + dis ) { ways2 [ y ] += ways2 [ x ] ; } } }