Storing distance from end2 to node u
dist2 [ u ] = 1 + dist2 [ p ] ; for ( let i = 0 ; i < adj [ u ] . length ; i ++ ) { if ( adj [ u ] [ i ] != p ) { findDistancefromSecond ( adj [ u ] [ i ] , u ) ; } } } function findNodes ( ) { let n = 5 ;