#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> maps[2005];
stack<int> pri;
int pre[2005], low[2005], answer[2005], num, tmp;
void dfs(int a) {
  int b, i;
  pre[a] = low[a] = ++num;
  pri.push(a);
  for (i = 0; i < maps[a].size(); i++) {
    b = maps[a][i];
    if (!pre[b]) {
      dfs(b);
      low[a] = min(low[a], low[b]);
    } else if (!answer[b])
      low[a] = min(low[a], pre[b]);
  }
  if (low[a] == pre[a]) {
    tmp++;
    while (1) {
      int c = pri.top();
      pri.pop();
      answer[c] = tmp;
      if (c == a) break;
    }
  }
}
void solve() {
  memset(pre, 0, sizeof(pre));
  memset(answer, 0, sizeof(answer));
  int i;
  num = tmp = 0;
  for (i = 1; i <= n; i++) {
    if (!pre[i]) dfs(i);
  }
}
void add(int a, int b) { maps[a].push_back(b); }
int main() {
  scanf("%d", &n);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int x;
      scanf("%d", &x);
      if (x) add(i, j);
    }
  }
  solve();
  if (tmp == 1 || tmp == 0)
    printf("YES\n");
  else
    printf("NO\n");
}
