#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; using bits = bitset<2000>; // using bits = bitset<20>; struct matrix{ int n, m; vector dat; matrix(int n_, int m_){ n = n_; m = m_; for(int i = 0; i < n; i++){ dat.push_back(bits()); } } bits& operator[](int x) { return dat[x]; } }; bool prod(matrix a, matrix b, matrix &ans){ assert(a.m == b.n); for(int i = 0; i < a.n; i++){ ans[i] = bits(); for(int j = 0; j < b.m; j++){ if((a.dat[i]&b.dat[j]) != 0) { ans[i][j] = 1; } } } return true; } void copy_mat(matrix a, matrix &b){ assert(a.n == b.n); assert(a.m == b.m); for(int i = 0; i < a.n; i++){ for(int j = 0; j < a.m; j++){ b.dat[i][j] = a.dat[i][j]; } } } void pow_mat(matrix a, ll n, matrix &ans){ assert(n < ((ll)1<<12)); matrix buf(a.n, a.n); matrix tmp(a.n, a.n); copy_mat(a, tmp); for(int i = 0; i < a.n; i++) { for(int j = 0; j < a.n; j++){ ans.dat[i][j] = 0; } ans.dat[i][i] = 1; } for(int i = 0; i <= 12; i++){ ll m = (ll)1 << i; if(m&n){ prod(tmp, ans, buf); copy_mat(buf, ans); } prod(tmp, tmp, buf); copy_mat(buf, tmp); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int v; ll d; cin >> v >> d; d = min((ll)2*v, d); matrix e(v, v), p(v, v); for(int i = 0; i < v; i++) cin >> e[i]; // prod(e, e, p); pow_mat(e, d, p); for(int i = 0; i < v; i++){ for(int j = 0; j < v; j++){ if(p[i][j] == 0) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; }