#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
int n, tmp, num;
bool g[maxn][maxn];
int dfn[maxn], low[maxn];
bool flag[maxn];
stack<int> sta;
void dfs(int x) {
  dfn[x] = low[x] = ++tmp;
  flag[x] = 1;
  sta.push(x);
  for (int i = 1; i <= n; i++) {
    if (!g[x][i]) continue;
    int q = i;
    if (!dfn[q]) {
      dfs(q);
      low[x] = min(low[x], low[q]);
    } else {
      if (flag[q]) low[x] = min(low[x], dfn[q]);
    }
  }
  if (dfn[x] == low[x]) {
    num++;
    while (sta.top() != x) flag[sta.top()] = 0, sta.pop();
    sta.pop();
    flag[x] = 0;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int x;
      scanf("%d", &x);
      if (x) g[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) dfs(i);
  }
  if (num == 1)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
