Storing valid dimensions as for every ( x , y ) both ( x , y ) and ( y , x ) are valid
for ( int i = 0 ; i < K ; i ++ ) { ok [ dimensions . elementAt ( i ) . first ] [ dimensions . elementAt ( i ) . second ] = true ; ok [ dimensions . elementAt ( i ) . second ] [ dimensions . elementAt ( i ) . first ] = true ; }