#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> G[2009];
int dfn[2009], low[2009], in[2009], dfs_time, top, stk[2009];
void tarjan(int i) {
  int j;
  dfn[i] = low[i] = ++dfs_time;
  in[i] = 1;
  stk[++top] = i;
  for (int k = 0; k < G[i].size(); k++) {
    j = G[i][k];
    if (!dfn[j]) {
      tarjan(j);
      low[i] = min(low[i], low[j]);
    } else if (in[j])
      low[i] = min(low[i], dfn[j]);
  }
  if (dfn[i] == low[i]) {
    cnt++;
    do {
      j = stk[top--];
      in[j] = 0;
    } while (i != j);
  }
}
int main() {
  scanf("%d", &n);
  int x;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &x);
      if (x != 0) G[i].push_back(j);
    }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  if (cnt == 1)
    printf("YES");
  else
    printf("NO");
}
