#include <bits/stdc++.h>
using namespace std;
struct data {
  int next, num;
} edge[5000001];
int n, tot = 0, numx = 0, headx = 0;
int head[100001], dfn[100001], low[100001], q[100001], fa[100001];
bool ins[100001], vis[100001];
void add(int u, int v) {
  edge[++tot].next = head[u];
  edge[tot].num = v;
  head[u] = tot;
  return;
}
void Tarjan(int x) {
  dfn[x] = ++numx;
  low[x] = dfn[x];
  q[++headx] = x;
  vis[x] = 1;
  ins[x] = 1;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int kx = edge[i].num;
    if (vis[kx]) {
      if (ins[kx]) low[x] = min(low[x], dfn[kx]);
      continue;
    }
    Tarjan(kx);
    low[x] = min(low[x], low[kx]);
  }
  if (low[x] < dfn[x]) return;
  while (q[headx] != x) {
    fa[q[headx]] = x;
    ins[q[headx]] = 0;
    headx--;
  }
  ins[x] = 0;
  fa[x] = x;
  headx--;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int x;
      scanf("%d", &x);
      if (x) add(i, j);
    }
  Tarjan(1);
  for (int i = 2; i <= n; i++)
    if (fa[i] != fa[1]) {
      printf("NO\n");
      return 0;
    }
  printf("YES\n");
  return 0;
}
