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