#include using namespace std; using pi = pair; const int inf = 1e6; signed main() { int v, d; cin >> v >> d; vector> G(v, vector(v, false)); for (int i = 0; i < v; ++i) { string s; cin >> s; for (int j = 0; j < v; ++j) if (s[j] == '1') G[i][j] = true; } vector> D(v, vector(v, pi(inf,inf))); bool valid = true; for (int src = 0; valid && src < v; ++src) { queue que; que.push(pi(src, 0)); vector evis(v, false), ovis(evis); while (!que.empty()) { pi q(que.front()); que.pop(); if(q.second%2){ ovis[q.first] = true; D[q.first][src].first = min(D[q.first][src].first, q.second); } else{ evis[q.first] = true; D[q.first][src].second = min(D[q.first][src].second, q.second); } D[src][q.first] = D[q.first][src]; for (int i = 0; i < v; ++i) if (!(q.second%2?evis:ovis)[i] && G[q.first][i]) que.push(pi(i, q.second + 1)); } for (int i = 0; valid && i < v;++i){ if (!(d % 2 ? ovis : evis)[i]) valid = false; if ((d % 2 ? D[src][i].first : D[src][i].second) > d) valid = false; } } cout << (valid ? "Yes" : ":("); }