#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define outl(x) cout << x << endl #define SP << " " << #define inf 1e18 using namespace std; typedef long long llint; typedef long long ll; typedef pair P; ll n, d; vector G[4005]; ll dist[4005][4005]; void bfs(vector G[], int S, llint dist[]) { queue Q; Q.push(S); for(int i = 1; i <= 2*n; i++) dist[i] = inf; dist[S] = 0; while(Q.size()){ int v = Q.front(); Q.pop(); for(int i = 0; i < G[v].size(); i++){ if(dist[G[v][i]] < inf/2) continue; Q.push(G[v][i]); dist[G[v][i]] = dist[v] + 1; } } } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> d; char e; rep(i, 1, n) rep(j, 1, n){ cin >> e; if(e == '1') G[i].push_back(n+j), G[n+i].push_back(j); } rep(i, 1, n) bfs(G, i, dist[i]); rep(i, 1, n) rep(j, 1, n){ if(d % 2 == 0 && dist[i][j] > d){ cout << "No" << endl; return 0; } if(d % 2 && dist[i][n+j] > d){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }