#include <bits/stdc++.h>
#include "testlib.h"
#define WA quitf(_wa,"The answer is wrong.\n")
#define AC quitf(_ok,"The answer is correct.\n")
using namespace std;
const int maxn=505;
const int INF=0x3f3f3f3f;
string s;
int n,d[maxn][maxn];
int main(int argc, char* argv[]){
	memset(d,INF,sizeof(d));
	registerTestlibCmd(argc, argv);
	n=inf.readInt();
//	scanf("%d",&n);
	s=ouf.readString();
//	cin>>s;
	if (s=="NO" && (n==2 || n==4)) AC;
	if (s!="YES" && s!="NO") WA;
	else if ((n==2 || n==4) && s=="YES") WA;
	else if (n!=2 && n!=4 && s=="NO") WA;
	for (int i=1;i<=n;i++){
		for (int j=1,x;j<=n;j++){
//			scanf("%d",&x);
			x=ouf.readInt();
			if (x!=0 && x!=1) WA;
			if (i==j && x) WA;
			if (x) d[i][j]=x;
		}
	}
	for (int i=1;i<=n;i++) d[i][i]=0;
//	putchar('q');
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j && d[i][j]==d[j][i]) WA;
//	putchar('q');
	for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (d[i][j]>2) WA;
//			printf("%d ",d[i][j]);
		}
//		putchar('\n');
	}
//	putchar('A');
	AC;
	return 0;
}
