#include <bits/stdc++.h>
using namespace std;
bool seen[2048][2048];
int N;
void dfs(int x, int* lvl, int* idx, stack<int>& S, int& nr, int& cur_level,
         bool* seen) {
  lvl[x] = idx[x] = cur_level++;
  S.push(x);
  seen[x] = true;
  for (int i = 0; i < N; i++)
    if (::seen[x][i]) {
      if (lvl[i] == -1) {
        dfs(i, lvl, idx, S, nr, cur_level, seen);
        if (lvl[i] < lvl[x]) lvl[x] = lvl[i];
      } else if (seen[i] && idx[i] < lvl[x]) {
        lvl[x] = idx[i];
      }
    }
  if (lvl[x] == idx[x]) {
    nr++;
    while (!S.empty()) {
      int next_x = S.top();
      seen[next_x] = false;
      S.pop();
      if (next_x == x) break;
    }
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      int x;
      scanf("%d", &x);
      if (x != 0) seen[i][j] = true;
    }
  int nr = 0;
  int* lvl = new int[2048];
  int* idx = new int[2048];
  bool* seen = new bool[2048];
  memset(lvl, -1, 2048 * sizeof(int));
  memset(seen, 0, 2048 * sizeof(bool));
  stack<int> S;
  int cur_level = 0;
  dfs(0, lvl, idx, S, nr, cur_level, seen);
  for (int i = 0; i < N; i++)
    if (lvl[i] == -1) {
      printf("NO\n");
      return 0;
    }
  if (nr != 1)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
