#include <bits/stdc++.h>
using namespace std;
bool g[2020][2020];
int n, m, k;
bool vis[2020];
void dfs1(int v, int fa) {
  vis[v] = true;
  for (int i = 1; i <= n; i++) {
    if (i != v && i != fa && !vis[i] && g[v][i]) {
      dfs1(i, v);
    }
  }
}
void dfs2(int v, int fa) {
  vis[v] = true;
  for (int i = 1; i <= n; i++) {
    if (i != v && i != fa && !vis[i] && g[i][v]) {
      dfs2(i, v);
    }
  }
}
int main() {
  scanf("%d", &n);
  memset(g, false, sizeof g);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &k);
      if (k)
        g[i][j] = 1;
      else
        g[i][j] = 0;
    }
  memset(vis, false, sizeof vis);
  dfs1(1, -1);
  bool ok = true;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      ok = false;
      break;
    }
  if (ok) {
    memset(vis, 0, sizeof vis);
    dfs2(1, -1);
    for (int j = 1; j <= n; j++) {
      if (!vis[j]) {
        ok = false;
        break;
      }
    }
  }
  if (ok)
    puts("YES");
  else
    puts("NO");
  return 0;
}
