#include #include #include #include using namespace std; #define CIN( LL , A ) LL A; cin >> A #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( remove_const::type >::type VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #include #define MAIN main int main() { constexpr const int bound = 31; CIN( int , N ); int T[bound][bound]; FOR( i , 0 , N ){ int ( &Ti )[bound] = T[i]; FOR( j , 0 , N ){ cin >> Ti[j]; } } FOR( n0 , 0 , N ){ int ( &Tn0 )[bound] = T[n0]; FOR( n1 , 0 , N ){ int& Tn0n1 = Tn0[n1]; int ( &Tn1 )[bound] = T[n1]; FOR( n2 , 0 , N ){ if( T[Tn0n1][n2] != Tn0[Tn1[n2]] ){ RETURN( "NO" ); } } } } bool unit; FOR( e , 0 , N ){ int ( &Te )[bound] = T[e]; unit = true; FOR( n , 0 , N ){ if( Te[n] != n ){ unit = false; break; } else if( T[n][e] != n ){ unit = false; break; } } if( unit ){ FOR( n , 0 , N ){ int ( &Tn )[bound] = T[n]; unit = false; FOR( i , 0 , N ){ if( Tn[i] == e ){ if( T[i][n] == e ){ unit = true; break; } else { RETURN( "NO" ); } } } if( ! unit ){ RETURN( "NO" ); } } } } RETURN( "YES" ); }