#include <bits/stdc++.h>
using namespace std;
const int N = 2003;
struct node {
  int y, next;
} a[N * N];
int head[N], dfn[N], low[N], i, j, k, n, m, g, d, s, T;
char c;
int read() {
  int z = 0;
  do c = getchar();
  while (c < '0' || c > '9');
  while (c >= '0' && c <= '9') z *= 10, z += c - '0', c = getchar();
  return z;
}
void jb(int x, int y) {
  if (read()) a[++k] = (node){y, head[x]}, head[x] = k;
}
void dfs(int w) {
  ++s, dfn[w] = low[w] = ++T;
  for (register int j = head[w]; j; j = a[j].next) {
    int c = a[j].y;
    if (!dfn[c])
      dfs(c), low[w] = min(low[w], low[c]);
    else
      low[w] = min(low[w], dfn[c]);
  }
  if (dfn[w] == low[w]) {
    puts(s != n || w != 1 ? "NO" : "YES");
    exit(0);
  }
}
int main() {
  n = read();
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) jb(i, j);
  dfs(1);
}
