#include using namespace std; int main() { int v, d; cin >> v >> d; using bs = bitset<1000>; vector E(v); for (auto& i : E) { string str; cin >> str; reverse(str.begin(), str.end()); i = bs(str); } for (int i = 0; i < v; ++i) { bs reachable = E[i], back1, back2; back1[i] = true; // already consumed 1 turn for reachable for (int j = 0; j < d - 1; ++j) { bs diff = reachable ^ back2; // back1 ^ back2 if (diff.none()) break; back2 = back1; for (int k = diff._Find_first(); k < v; k = diff._Find_next(k)) back1 |= E[k]; swap(reachable, back1); } if (reachable.count() < v) return cout << "No" << endl, 0; } cout << "Yes" << endl; }