#include using namespace std; using ll = long long; using vec = vector; using vecvec = vector; #define endl "\n" #define rep_0() for (ll i = 0;; i++) #define rep_1(n) for (ll _i = 0; _i < (ll)(n); _i++) #define rep_2(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep_3(i, s, n) for (ll i = s; i < (ll)(n); i++) #define rep_4(i, s, n, d) for (ll i = s; i < (ll)(n); i+=d) #define rep_x(x, a, b, c, d, F, ...) F #define rep(...) rep_x(,##__VA_ARGS__,rep_4(__VA_ARGS__),rep_3(__VA_ARGS__),rep_2(__VA_ARGS__),rep_1(__VA_ARGS__),rep_0(__VA_ARGS__)) #define len(x) (ll)((x).size()) #define all(x) (x).begin(),(x).end() #define sum(v) accumulate(all(v)) #define MAX(v) *max_element(all(v)) #define MIN(v) *min_element(all(v)) #define append push_back constexpr ll INF = 1'010'000'000'000'000'017LL; constexpr ll MOD = 1'000'000'007LL; ll v, d, digits; bool g[2000][2000], ans[2000][2000]; string edge[2000]; void power(ll sz, bool a[][2000], bool b[][2000]) { bool res[2000][2000]; rep(i, sz) rep(j, sz) res[i][j] = false; rep(i, sz) rep(j, sz) rep(k, sz) if (a[i][k] & b[k][j]) { res[i][j] = true; break; } rep(i, sz) rep(j, sz) a[i][j] = res[i][j]; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> v >> d; rep(i, v) cin >> edge[i]; rep(i, v) rep(j, v) { g[i][j] = (edge[i][j] == '1'); ans[i][j] = (i == j); } while (d) { if (d & 1) power(v, ans, g); power(v, g, g); d >>= 1; } rep(i, v) rep(j, v) if (!ans[i][j]) { puts("No"); return 0; } puts("Yes"); }