Function to perform calculations .
function solve ( arr ) { let i = 0 ; while ( i < p ) { let q = arr [ i ] [ 0 ] ; let h = arr [ i ] [ 1 ] ; let t = arr [ i ] [ 2 ] ; cd [ q ] = h ; wt [ q ] = t ; rd [ h ] = q ; i ++ ; } a = [ ] ; b = [ ] ; c = [ ] ; for ( let j = 1 ; j <= n ; ++ j )