#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)); bitset<1000> evis, ovis; while (!que.empty()) { pi q(que.front()); que.pop(); if(q.second%2){ if (ovis[q.first]) continue; ovis.set(q.first); D[q.first][src].first = min(D[q.first][src].first, q.second); } else if(q.second>0){ if (evis[q.first]) continue; evis.set(q.first); 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)); } if ((d % 2 && ovis.count() < v) || (d % 2 == 0 && evis.count() < v)) valid = false; if(d%2){ for (int i = 0; valid && i < v; ++i) if (D[src][i].first > d) valid = false; } else{ for (int i = 0; valid && i < v; ++i) if (D[src][i].second > d) valid = false; } } cout << (valid ? "Yes" : ":("); }