#include <bits/stdc++.h>
using namespace std;
int cont, N;
bitset<2001> V;
bitset<2001> G[2001];
void dfs(int nod) {
  cont++;
  V[nod] = true;
  for (int j = 0; j < N; j++) {
    if (!V[j] and G[nod][j]) {
      dfs(j);
    }
  }
}
struct matrix {
  int A[10][10];
  matrix() { memset(A, 0, sizeof A); }
  int operator()(int a, int b) const { return A[a][b]; }
  int& operator()(int a, int b) { return A[a][b]; }
  matrix operator*(matrix B) {
    matrix ans;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        for (int k = 0; k < N; k++) {
          int temp = A[i][k] * B(k, j);
          ans(i, j) += temp;
        }
      }
    }
    return ans;
  }
  matrix pow(int n) {
    matrix ans;
    for (int i = 0; i < N; i++) {
      ans(i, i) = 1;
    }
    matrix BASE;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        BASE(i, j) = A[i][j];
      }
    }
    if (n == 0) return ans;
    if (n == 1) return BASE;
    while (n) {
      if (n & 1) ans = ans * BASE;
      BASE = BASE * BASE;
      n = n >> 1;
    }
    return ans;
  }
};
ostream& operator<<(ostream& os, const matrix M) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      os << (M.A[i][j]);
      if (j < N - 1) os << " ";
    }
    if (i < N - 1) os << endl;
  }
  return os;
}
int main() {
  scanf("%d\n", &N);
  memset(G, 0, sizeof G);
  int nod;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int x;
      scanf("%d", &x);
      bool tmp = (x != 0);
      G[i][j] = tmp;
      if (x and i == j) {
        nod = i;
      }
    }
  }
  cont = 0;
  V.reset();
  dfs(nod);
  int R = cont;
  cont = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      bool tmp = G[i][j];
      G[i][j] = G[j][i];
      G[j][i] = tmp;
    }
  }
  V.reset();
  dfs(nod);
  int K = cont;
  if (R == N and K == N)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
