#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const multiset<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
vector<long long> adj[2002];
vector<bool> vis(2002, false);
void dfs(long long v, stack<long long>& S) {
  vis[v] = true;
  for (auto& u : adj[v]) {
    if (not vis[u]) dfs(u, S);
  }
  S.push(v);
}
void solve() {
  long long n;
  cin >> n;
  long long temp;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cin >> temp;
      if (temp) {
        adj[i].push_back(j);
      }
    }
  }
  stack<long long> S;
  for (long long i = 0; i < n; i++)
    if (not vis[i]) dfs(i, S);
  vector<long long> adj2[2002];
  for (long long i = 0; i < n; i++) {
    for (auto& j : adj[i]) adj2[j].push_back(i);
  }
  for (long long i = 0; i < n; i++) {
    adj[i] = adj2[i];
  }
  vis = vector<bool>(2002, false);
  long long ctr = 0;
  while (not S.empty()) {
    long long s = S.top();
    S.pop();
    if (not vis[s]) {
      ctr++;
      if (ctr == 2) {
        cout << "NO\n";
        return;
      }
      dfs(s, S);
    }
  }
  cout << "YES\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
}
