#include <bits/stdc++.h>
using namespace std;
int n, m;
int head[4000005], pos;
int bcnt, belong[4000005], pre[4000005], cok;
int top, stk[4000005];
struct L {
  int v, nxt;
} e[4000005];
void add(int u, int v) {
  e[pos].v = v;
  e[pos].nxt = head[u];
  head[u] = pos++;
}
void InitEdge() {
  memset(head, -1, sizeof(head));
  pos = 0;
}
int dfs(int u) {
  int lowu = pre[u] = ++cok;
  stk[top++] = u;
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].v;
    if (!pre[v]) {
      int lowv = dfs(v);
      lowu = min(lowu, lowv);
    } else if (!belong[v])
      lowu = min(lowu, pre[v]);
  }
  if (lowu == pre[u]) {
    bcnt++;
    do {
      belong[stk[top - 1]] = bcnt;
    } while (stk[--top] != u);
  }
  return lowu;
}
void tarjan() {
  top = cok = bcnt = 0;
  memset(pre, 0, sizeof(pre));
  memset(belong, 0, sizeof(belong));
  for (int i = 1; i <= n; i++)
    if (!pre[i]) dfs(i);
}
int main() {
  while (~scanf("%d", &n)) {
    int x;
    InitEdge();
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        scanf("%d", &x);
        if (i != j && x) {
          add(i, j);
        }
      }
    }
    tarjan();
    if (bcnt > 1)
      puts("NO");
    else
      puts("YES");
  }
}
