#pragma GCC optimize("O3") #include #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) using namespace std; using vv=vector>; const ll MOD=1e9+7; vv E(int n) //行列の初期化(単位行列) { vv res(n, vector(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) res[i][j] = (i == j); //対角成分を1に、それ以外を0にする。 return res; } vv matprod(vv A, vv B) //行列の掛け算 { int l = A.size(), m = B.size(), n = B[0].size(); vv res(l, vector(n, 0)); for (int i = 0; i < l; i++) for (int j = 0; j < n; j++) for (int k = 0; k < m; k++) res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD; return res; } vv matpow(vv A, ll n) //行列累乗 { vv p = A, res = E(A.size()); while (n > 0) { if (n & 1) res = matprod(res, p); p = matprod(p, p); n >>= 1; } return res; } int main() { ll m, k; cin >> m >> k; vv tran(m, vector(m, 0)); //tranは写像f:A(m)→A(m)を表す行列 for (int i = 0; i < m; i++) for (int t = 0; t < m; t++) { char c; cin >> c; ll num=c-'0'; tran[i][t]=num; } tran = matpow(tran, k); bool ok=true; rep(i,m){ rep(j,m){ if(tran[i][j]==0) ok=false; } } if(ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }