import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import core.bitop;

void main ()
{
	int n;
	while (scanf (" %d", &n) > 0)
	{
		int m = (n + 31) / 32;
		auto a1 = new uint [] [] (n, m);
		auto a2 = new uint [] [] (n, m);
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				int c;
				scanf (" %d", &c);
				if (c)
				{
					a1[i][j >> 5] |= 1u << (j & 31);
					a2[j][i >> 5] |= 1u << (i & 31);
				}
			}
		}

		auto b = new bool [n];
		uint [] [] a;

		void recur (int v)
		{
			b[v] = true;
			foreach (u; 0..n)
			{
				if (!b[u] && (a[v][u >> 5] & (1u << (u & 31))))
				{
					recur (u);
				}
			}
		}
		
		bool ok = true;

		b[] = false;
		a = a1;
		recur (0);
		ok &= all !("a == true") (b[]);

		b[] = false;
		a = a2;
		recur (0);
		ok &= all !("a == true") (b[]);

		writeln (ok ? "YES" : "NO");
	}
}
