#include <bits/stdc++.h>
using namespace std;
const int V = 2100;
vector<int> vec[V];
int id[V], pre[V], low[V], s[V], stop, cnt, scnt;
void tarjan(int v, int n) {
  int t, minc = low[v] = pre[v] = cnt++;
  vector<int>::iterator pv;
  s[stop++] = v;
  for (pv = vec[v].begin(); pv != vec[v].end(); ++pv) {
    if (-1 == pre[*pv]) tarjan(*pv, n);
    if (low[*pv] < minc) minc = low[*pv];
  }
  if (minc < low[v]) {
    low[v] = minc;
    return;
  }
  do {
    id[t = s[--stop]] = scnt;
    low[t] = n;
  } while (t != v);
  ++scnt;
}
int main() {
  int n, v;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      scanf("%d", &v);
      if (v != 0) vec[i].push_back(j);
    }
  stop = cnt = scnt = 0;
  for (int i = 0; i < n; i++) pre[i] = -1;
  for (int i = 0; i < n; ++i) {
    if (-1 == pre[i]) tarjan(i, n);
  }
  if (scnt == 1)
    puts("YES");
  else
    puts("NO");
  return 0;
}
