#include using namespace std; #define rep(i,n) for(int i = 0; i < int(n); ++i) #define rrep(i,n) for(int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; bitset<2000> e[2000], et[2000], now[2000], tmp[2000]; int main() { ios::sync_with_stdio(false); cin.tie(0); int v; ll d; cin >> v >> d; assert(v <= 2000); rep(i, v) rep(j, v) { char t; cin >> t; e[i][j] = t - '0'; } rep(i, v) now[i][i] = 1; while(d) { rep(i, v) rep(j, v) et[j][i] = e[i][j]; if (d & 1) { rep(i, v) tmp[i] = now[i]; rep(i, v) rep(j, v) now[i][j] = (tmp[i] & et[j]).any(); } rep(i, v) tmp[i] = e[i]; rep(i, v) rep(j, v) e[i][j] = (tmp[i] & et[j]).any(); d >>= 1; } bool ok = true; rep(i, v) rep(j, v) if (!now[i][j]) ok = false; cout << (ok ? "Yes\n" : "No\n"); }