#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
int n, x, k, h[N];
vector<int> tp, v[N], v2[N];
void dfs(int x) {
  h[x] = 1;
  for (int i = 0; i <= (int)v[x].size() - 1; i++)
    if (!h[v[x][i]]) dfs(v[x][i]);
  tp.push_back(x);
}
void dfs2(int x) {
  h[x] = 2;
  for (int i = 0; i <= (int)v2[x].size() - 1; i++)
    if (h[v2[x][i]] != 2) dfs2(v2[x][i]);
  tp.push_back(x);
}
void scc() {
  for (int i = 1; i <= n; i++)
    if (!h[i]) dfs(i);
  for (int i = n - 1; i >= 0; i--) {
    if (h[tp[i]] == 2) continue;
    k++;
    dfs2(tp[i]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &x);
      if (x) v[i].push_back(j), v2[j].push_back(i);
    }
  scc();
  if (k == 1)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
