#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int MOD = 1e9 + 7;
const int N = 2000;
vector<vector<int> > g, gr;
vector<char> used;
vector<int> order, component;
void dfs1(int v) {
  used[v] = true;
  for (size_t i = 0; i < g[v].size(); ++i)
    if (!used[g[v][i]]) dfs1(g[v][i]);
  order.push_back(v);
}
void dfs2(int v) {
  used[v] = true;
  component.push_back(v);
  for (size_t i = 0; i < gr[v].size(); ++i)
    if (!used[gr[v][i]]) dfs2(gr[v][i]);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(20);
  int n;
  cin >> n;
  g.resize(n);
  gr.resize(n);
  vector<bitset<N> > aa(N);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int a;
      cin >> a;
      if (i != j && a) {
        gr[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }
  used.assign(n, false);
  for (int i = 0; i < n; ++i)
    if (!used[i]) dfs1(i);
  used.assign(n, false);
  int kol = 0;
  for (int i = 0; i < n; ++i) {
    int v = order[n - 1 - i];
    if (!used[v]) {
      dfs2(v);
      kol++;
      component.clear();
    }
  }
  if (kol == 1) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
}
