#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int a[N][N], low[N], d[N], ttime, n;
void dfs(int u) {
  d[u] = low[u] = ttime++;
  for (int v = 0; v < n; ++v)
    if (a[u][v] > 0) {
      if (d[v] == -1) {
        dfs(v);
        low[u] = min(low[u], low[v]);
      } else {
        low[u] = min(low[u], d[v]);
      }
    }
  if (low[u] == d[u]) {
    puts(u == 0 && ttime == n ? "YES" : "NO");
    exit(0);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) cin >> a[i][j];
  memset(d, -1, sizeof d);
  dfs(0);
  return 0;
}
