#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n;
bool a[N][N], v[2][N];
void dfs(int &x, int &father, int &val) {
  v[val][x] = 1;
  for (int j = 1; j <= n; ++j)
    if (!v[val][j] && j != father)
      if ((val && a[x][j]) || (!val && a[j][x])) dfs(j, x, val);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      int x;
      scanf("%d", &x);
      if (x && i != j) a[i][j] = 1;
    }
  int a = 1, b = 0, c = -1;
  dfs(a, c, b);
  dfs(a, c, a);
  for (int i = 1; i <= n; ++i)
    if (!(v[0][i] * v[1][i])) {
      printf("NO");
      return 0;
    }
  printf("YES");
}
