#include <bits/stdc++.h>
int n;
int tot;
int top;
int tot1;
int a[2005][2005];
int stack[2005];
int instack[2005];
int visit[2005];
int dfn[2005];
int low[2005];
inline void tarjan(int u) {
  if (visit[u]) return;
  int v;
  dfn[u] = low[u] = ++tot;
  stack[++top] = u;
  instack[u] = 1;
  visit[u] = 1;
  int i;
  for (i = 1; i <= n; i++) {
    if (a[u][i]) {
      if (!visit[i]) {
        tarjan(i);
        if (low[i] < low[u]) low[u] = low[i];
      } else {
        if (instack[i])
          if (dfn[i] < low[u]) low[u] = dfn[i];
      };
    };
  };
  if (dfn[u] == low[u]) {
    ++tot1;
    while (1) {
      v = stack[top--];
      instack[v] = 0;
      if (v == u) break;
    };
  };
};
int main() {
  scanf("%d", &n);
  int i, j;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%d", a[i] + j);
    };
  };
  for (i = 1; i <= n; i++) tarjan(i);
  puts(tot1 == 1 ? "YES" : "NO");
}
