O(n^3)水过
#include <bits/stdc++.h>
using namespace std;
int mt1[501][501];
int mt2[501][501];
int mt3[501][501];
int mt4[501][501];
int n;
template <class T>
inline bool scan_d(T &ret)
{
char c;
int sgn;
if(c=getchar(),c==EOF) return 0; //EOF
while(c!='-'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
ret*=sgn;
return 1;
}
int mult()
{
for(int i = 0; i < n; ++i)
for(int k = 0; k < n; ++k)
for(int j = 0; j < n; ++j)
mt4[i][j] += mt1[i][k]*mt2[k][j];
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < n; ++j)
if(mt4[i][j] != mt3[i][j])
return false;
}
return true;
}
int main()
{
scan_d(n);
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
scan_d(mt1[i][j]);
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
scan_d(mt2[i][j]);
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
scan_d(mt3[i][j]);
if(mult())
printf("Yes\n");
else
printf("No\n");
return 0;
}