#include <bits/stdc++.h>
using namespace std;
int n, a, it;
vector<int> e[2000];
vector<int> S;
int dfs_num[2000], dfs_low[2000], dfsNumberCounter, visited[2000], numSCC,
    SCC[2000];
void tarjanSCC(int u) {
  dfs_low[u] = dfs_num[u] = ++dfsNumberCounter;
  S.push_back(u);
  visited[u] = 1;
  for (int j = 0; j < (int)e[u].size(); j++) {
    int v = e[u][j];
    if (dfs_num[v] == 0) {
      tarjanSCC(v);
    }
    if (visited[v]) {
      dfs_low[u] = min(dfs_low[u], dfs_low[v]);
    }
  }
  if (dfs_low[u] == dfs_num[u]) {
    numSCC++;
    while (1) {
      int v = S.back();
      S.pop_back();
      visited[v] = 0;
      SCC[numSCC]++;
      if (u == v) break;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a);
      if (a) {
        e[i].push_back(j);
      }
    }
  }
  tarjanSCC(0);
  for (int i = 0; i <= numSCC; i++) {
    if (SCC[i] == n) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}
