//#define _GLIBCXX_DEBUG #include //#include using ll = long long; using ld = long double; #define FOR(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++) #define rep(i, n) FOR(i, 0, n) #define rFOR(i, a, b) for(ll i = (ll)(a - 1); i >= (ll)(b); i--) #define rrep(i, a) rFOR(i, a, 0) #define all(c) begin(c),end(c) using namespace std; typedef pair P; typedef vector vl; typedef vector vvl; typedef vector

vP; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge{ll to, cost;}; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } const long long MXV = 1000; vector G[MXV]; vector d(MXV,vvl(MXV, vl(2,INF))); void dijkstra(int i,int s){ priority_queue, vector>, greater>> pq; d[i][s][0] = 0; pair q; q.first=P(0,s);q.second=0; pq.push(q); while(pq.size()){ pair p = pq.top(); pq.pop(); int V = p.first.second; int sig=p.second; if(d[i][V][sig] < p.first.first){ continue; } rep(k,G[V].size()){ edge e = G[V][k]; if(d[i][e.to][1^sig] > d[i][V][sig] + e.cost){ d[i][e.to][1^sig] = d[i][V][sig] + e.cost; pair neko; neko.first=P(d[i][e.to][1^sig],e.to); neko.second=1^sig; pq.push(neko); } } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll V,D; cin >> V >> D; vector> A(V,vector(V)); bool ok=true; rep(i,V){ rep(j,V){ cin >> A[i][j]; if(A[i][j]=='0') ok=false; } } rep(i,V){ rep(j,V){ if(A[i][j]=='1'){ edge e; e.to=j; e.cost=1; G[i].push_back(e); } } } if(D==1&&(!ok)){ cout << "No" << endl; return 0; } ll parity=D%2; rep(i,V){ dijkstra(i,i); rep(j,V){ if(d[i][j][parity]>D){ cout << "No" << endl; return 0; } } } cout << "Yes" << endl; }