#pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include #include #include #include #include using namespace std; #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define COUT( ANSWER ) cout << ( ANSWER ) << "\n" #define RETURN( ANSWER ) COUT( ANSWER ); QUIT int main() { UNTIE; CEXPR( int , bound , 30 ); CIN_ASSERT( N , 0 , bound ); int T[bound][bound]; FOR( i , 0 , N ){ int ( &Ti )[bound] = T[i]; FOR( j , 0 , N ){ CIN_ASSERT( Tij , 0 , N - 1 ); Ti[j] = Tij; } } 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" ); } } RETURN( "No" ); }