#include <bits/stdc++.h>
using namespace std;
int N;
bool v[2001];
vector<int> G[2001];
int cnt = 0;
int a[2001][2001];
int Dfn[2001], Low[2001];
int Dindex = 0;
int Bcnt;
bool instack[2001];
int Sta[2001];
int top = -1;
void add(int x, int y) { G[x].push_back(y); }
void read() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) {
      scanf("%d", &a[i][j]);
    }
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      if (a[i][j] && i != j) add(i, j);
}
void tarjan(int v) {
  Dfn[v] = Low[v] = ++Dindex;
  instack[v] = 1;
  Sta[++top] = v;
  for (int i = 0; i < G[v].size(); ++i) {
    int w = G[v][i];
    if (!Dfn[w]) {
      tarjan(w);
      Low[v] = min(Low[v], Low[w]);
    } else if (instack[w])
      Low[v] = min(Low[v], Dfn[w]);
  }
  int j;
  if (Dfn[v] == Low[v]) {
    Bcnt++;
    do {
      j = Sta[top--];
      instack[j] = 0;
    } while (j != v);
  }
}
int main() {
  read();
  Bcnt = 0;
  for (int i = 0; i < N; ++i)
    if (!Dfn[i]) tarjan(i);
  if (Bcnt > 1)
    puts("NO");
  else
    puts("YES");
  return 0;
}
