Function performing calculations .
void solve ( int arr [ ] [ 3 ] ) { int i = 0 ; while ( i < p ) { int q = arr [ i ] [ 0 ] , h = arr [ i ] [ 1 ] , t = arr [ i ] [ 2 ] ; cd [ q ] = h ; wt [ q ] = t ; rd [ h ] = q ; i ++ ; } a . clear ( ) ; b . clear ( ) ; c . clear ( ) ; for ( int j = 1 ; j <= n ; ++ j )