#include <bits/stdc++.h>
using namespace std;
int dfn[5000];
int low[5000];
int instack[5000];
int cnt_scc;
int cnt;
stack<int> S;
vector<int> G[5000];
int tarjan(int u) {
  if (dfn[u] == -1) {
    dfn[u] = low[u] = cnt++;
    S.push(u);
    instack[u] = 1;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (dfn[v] == -1) {
        low[u] = min(low[u], tarjan(v));
      } else if (instack[v])
        low[u] = min(dfn[v], low[u]);
    }
    if (low[u] == dfn[u]) {
      while (instack[u]) instack[S.top()] = 0, S.pop();
      cnt_scc++;
    }
  }
  return low[u];
}
int main() {
  int n;
  scanf("%d", &n);
  memset(dfn, -1, sizeof(dfn));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int t;
      scanf("%d", &t);
      if (t) {
        G[i].push_back(j);
      }
    }
  }
  for (int i = 0; i < n; i++) tarjan(i);
  cout << (cnt_scc > 1 ? "NO" : "YES") << endl;
  return 0;
}
