//2012长春现场赛
很裸的2-sat 因为是位运算,所以 把b[i] 的 每一位都利用 2-sat 判断一次。
#include<stdio.h>
#include<string.h>
#include <cmath>
#include<algorithm>
#include <vector>
#include <iostream>
#include <stack>
#define fr(i,s,n) for(int i=s;i<n;i++)
#define fi freopen("in.txt","r",stdin)
#define cl(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
const int N=510*4;
int b[510][510];
vector<int> g[N];
int tot,Index;
int low[N],dfn[N],instack[N];
int belong[N];
stack<int> st;
class Sol
{
public:
int n;
void init()
{
tot=Index=0;
while(!st.empty()) st.pop();
fr(i,0,n*2) g[i].clear();
cl(dfn),cl(belong),cl(low),cl(instack);
}
bool read()
{
if (scanf("%d",&n)==EOF) return 0;
fr(i,0,n)
{
fr(j,0,n)
{
scanf("%d",&b[i][j]);
}
}
return 1;
}
bool check1()
{
fr(i,0,n)
{
if (b[i][i]!=0) return 0;
}
return 1;
}
void build()
{
fr(i,0,n)
{
fr(j,0,n)
{
if (i==j) continue;
if (b[i][j]&1)
{
if (i%2==1 && j%2 == 1)
{
g[ n+i ].push_back(j);
g[ n+j ].push_back(i);
}
else if (i%2==0 && j%2==0)
{
g[i].push_back(j);
g[j].push_back(i);
}
else
{
g[i].push_back(j+n);
g[j].push_back(i+n);
g[j+n].push_back(i);
g[i+n].push_back(j);
}
}
else
{
if (i%2==1 && j%2 == 1)
{
g[i+n].push_back(j+n);
g[j+n].push_back(i+n);
}
else if (i%2==0 && j%2==0)
{
g[i].push_back(j+n);
g[j].push_back(i+n);
}
else
{
g[i].push_back(j);
g[j].push_back(i);
g[i+n].push_back(j+n);
g[j+n].push_back(i+n);
}
}
}
}
}
void tarjan(int u)
{
dfn[u] = low[u] = ++Index;
instack[u] = 1;
st.push(u);
int v,size = g[u].size();
for(int i = 0; i < size; i++)
{
v = g[u][i];
if(!dfn[v])
{
tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(instack[v]) low[u] = min(low[u],dfn[v]);
}
if(dfn[u] == low[u])
{
tot++;
do
{
v = st.top();
st.pop();
belong[v] = tot; //同在一个belong集
instack[v] = 0;
}
while(v != u);
}
}
bool sol()
{
if (!check1()) return 0;
fr(k,0,32)
{
init();
build();
fr(i,0,2*n)
if(!dfn[i]) tarjan(i);
fr(i,0,n)
if(belong[i] == belong[i+n]) return 0;
fr(i,0,n)
{
fr(j,0,n)
{
b[i][j]>>=1;
}
}
}
return 1;
}
};
int main()
{
Sol s;
while(s.read())
{
bool flag=s.sol();
if (flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}