//#define _GLIBCXX_DEBUG #include //#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using ll = long long; using ld = long double; #define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(i, n) FOR(i, 0, n) #define rFOR(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--) #define rrep(i, a) rFOR(i, a, 0) #define all(c) begin(c),end(c) using namespace std; typedef pair P; typedef vector vl; typedef vector vvl; typedef vector

vP; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const int INF = 1e9; struct edge{ll to, cost;}; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } const int MXV = 2000; vector G[MXV]; vector>> d(MXV,vector>(MXV, vector(2,INF))); //bfsにかえる(dijkstraでいいじゃん) //なんで?笑 void dijkstra(int i,int s){ queue> pq; d[i][s][0] = 0; pair q; q.first=P(0,s);q.second=0; pq.push(q); while(pq.size()){ pair p = pq.front(); pq.pop(); int V = p.first.second; int sig=p.second; rep(k,G[V].size()){ int to = G[V][k]; if(d[i][to][1^sig] == INF){ d[i][to][1^sig] = d[i][V][sig] + 1; pair neko; neko.first=P(d[i][to][1^sig],to); neko.second=1^sig; pq.push(neko); } } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll V,D; cin >> V >> D; vector A(V); bool ok=true,ng=true; rep(i,V){ cin >> A[i]; rep(j,V){ if(A[i][j]=='0') ok=false; else ng=false; } } rep(i,V){ rep(j,V){ if(A[i][j]=='1'){ G[i].push_back(j); } } } if(ok){ cout << "Yes" << endl; return 0; } if(ng){ cout << "No" << endl; return 0; } if(D==1){ cout << "No" << endl; return 0; } ll parity=D%2; rep(i,V){ dijkstra(i,i); rep(j,V){ if(d[i][j][parity]>D){ cout << "No" << endl; return 0; } } } cout << "Yes" << endl; }