#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int arr[N][N], n;
vector<int> adj[N], revAdj[N];
bool visited[N];
vector<int> vec;
void dfs(int v) {
  visited[v] = 1;
  for (auto i : revAdj[v])
    if (!visited[i]) dfs(i);
  vec.push_back(v);
}
void dfs2(int v) {
  visited[v] = 1;
  for (auto i : adj[v])
    if (!visited[i]) dfs2(i);
}
void func() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> arr[i][j];
      if (arr[i][j]) arr[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j != i && arr[i][j]) {
        revAdj[j].push_back(i);
        adj[i].push_back(j);
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (!visited[i]) dfs(i);
  reverse(vec.begin(), vec.end());
  for (int i = 1; i <= n; i++) visited[i] = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[vec[i]]) {
      cnt++;
      if (cnt > 1) {
        cout << "NO\n";
        return;
      }
      dfs2(vec[i]);
    }
  }
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int ntc = 1;
  for (int i = 1; i <= ntc; i++) {
    func();
  }
  return 0;
}
