#include <bits/stdc++.h>
using namespace std;
int n;
int a[2100][2100];
int u[2100];
int o;
int order[2100];
void dfs2(int v) {
  u[v] = 2;
  for (int i = 1; i <= n; i++)
    if (u[i] != 2)
      if (a[i][v]) dfs2(i);
}
void dfs1(int v) {
  u[v] = 1;
  for (int i = 1; i <= n; i++)
    if (u[i] == 0)
      if (a[v][i]) dfs1(i);
  o++;
  order[o] = v;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (u[i] == 0) {
      dfs1(i);
    }
  }
  int C = 0;
  for (int i = n; i >= 1; i--) {
    if (u[order[i]] != 2) {
      dfs2(order[i]);
      C++;
    }
  }
  if (C == 1)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
