#include <bits/stdc++.h>
using namespace std;
int m, n, cou = 0, ncou = 0;
int dfn[10005] = {0}, h[10005] = {0}, nh[10005], low[10005], num = 0,
    from[10005] = {0}, cnt = 0, siz[10005] = {0};
bool stk[10005] = {false}, vis[10005] = {false};
int cd[10005] = {0};
struct Bian {
  int dian, pre;
} bian[4000005];
int s[10005], top;
void addedge(int a, int b) {
  cou++;
  bian[cou].dian = b;
  bian[cou].pre = h[a];
  h[a] = cou;
}
void tarjan(int o) {
  int i, v;
  num++;
  dfn[o] = low[o] = num;
  s[top] = o;
  top++;
  stk[o] = true;
  for (i = h[o]; i != 0; i = bian[i].pre) {
    v = bian[i].dian;
    if (!dfn[v]) {
      tarjan(v);
      low[o] = min(low[o], low[v]);
    } else if (stk[v])
      low[o] = min(low[o], dfn[v]);
  }
  if (dfn[o] == low[o]) {
    cnt++;
    while (s[top - 1] != o) {
      from[s[top - 1]] = cnt;
      stk[s[top - 1]] = false;
      top--;
      siz[cnt]++;
    }
    from[o] = cnt;
    top--;
    stk[o] = false;
    siz[cnt]++;
  }
  return;
}
int main() {
  int i, j, a, b;
  top = 1;
  num = 0;
  memset(dfn, 0, sizeof(dfn));
  memset(h, 0, sizeof(h));
  memset(nh, 0, sizeof(nh));
  memset(stk, 0, sizeof(stk));
  memset(from, 0, sizeof(from));
  memset(cd, 0, sizeof(cd));
  memset(vis, 0, sizeof(vis));
  memset(siz, 0, sizeof(siz));
  cnt = 0;
  cou = 0, ncou = 0;
  cin >> n;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      scanf("%d", &a);
      if (a) addedge(i, j);
    }
  for (i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  if (cnt == 1)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
  int mini = 0;
  for (i = 1; i <= cnt; i++)
    if (cd[i] == 0) {
      if (!mini)
        mini = i;
      else {
        cout << 0 << endl;
        return 0;
      }
    }
  cout << siz[mini] << endl;
  return 0;
}
