#include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define maxn 2005 #define put() putchar('\n') usingnamespace std; inlinevoidread(int &x){ int f=1;x=0;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();} x*=f; } int dfn[maxn],low[maxn],vis[maxn],stac[maxn],tot,sccnum,times; int a[maxn][maxn],n; inlinevoiddfs(int x){ //printf("%d %d\n",x,sccnum); int i;dfn[x]=low[x]=++times;vis[x]=1;stac[++tot]=x; for (i=1;i<=n;i++) { if (!a[x][i]||i==x) continue; if (!dfn[i]) dfs(i),low[x]=min(low[x],low[i]); elseif (vis[i]) low[x]=min(low[x],dfn[i]); } if (dfn[x]==low[x]) { ++sccnum; while (1) { vis[stac[tot]]=0; if (stac[tot--]==x) return; } } } signedmain(void){ //freopen("1.in","r",stdin); int i,j,tot=0; read(n); for (i=1;i<=n;i++) for (j=1;j<=n;j++) read(a[i][j]); for (i=1;i<=n;i++) if (!dfn[i]) dfs(i); puts(sccnum==1?"YES":"NO"); return0; }