#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vi; typedef pair pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template inline bool chmax(T &a, T b){ if(a inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } template class mat { private: // (or, and) の意味での積(正方かつ対称行列に限る(重みなし無向グラフの隣接行列とか)) mat operator*(const mat& m) const { mat ans; for(int i = 0; i < COL_SIZE; i++){ for(int j = 0; j < COL_SIZE; j++){ if(this->a[i][j] == 0) continue; ans.a[i] |= m.a[j]; } } return ans; } public: bitset* a; int r; // 正方行列の場合 mat() : mat(COL_SIZE){} // 一般の行列の場合 mat(int row_size) : r(row_size){ a = new bitset[r]; } int rank() const { int res = 0; mat b(r); for(int i = 0; i < r; i++) b[i] = a[i]; for(int i = 0; i < COL_SIZE; i++){ if(res == r) return res; int pivot = res; if(!b[pivot][i]){ for(int j = res + 1; j < r; j++){ if(b[j][i]){ pivot = j; break; } } if(!b[pivot][i]) continue; swap(b[pivot], b[res]); } for(int j = res + 1; j < r; j++){ if(b[j][i]) b[j] ^= b[res]; } res++; } return res; } inline const bitset& operator[](size_t index) const { return a[index]; } inline bitset& operator[](size_t index){ return a[index]; } friend mat pow(mat m, long long cnt){ mat res; for(int i = 0; i < COL_SIZE; i++) res[i][i] = 1; while(cnt){ if(cnt & 1){ res = res * m; } m = m * m; cnt >>= 1; } return res; } }; int main(){ mat<2000> M; int n; ll d; cin >> n >> d; rep(i,n){ string s; cin >> s; rep(j,n){ if(s[j]=='0'){ M[i][j] = 0; }else{ M[i][j] = 1; } } } if(d>=40000000)d = 40000000; mat<2000> X = pow(M,d); bool f = 1; rep(i,n){ rep(j,n){ if(!X[i][j])f = 0; } } if(f){ cout << "Yes\n"; }else{ cout << "No\n"; } return 0; }