import sys from collections import deque def main(): sys.setrecursionlimit(1 << 25) V, D = map(int, sys.stdin.readline().split()) E = [sys.stdin.readline().strip() for _ in range(V)] # Build adjacency list adj = [[] for _ in range(V)] for i in range(V): for j in range(V): if E[i][j] == '1' and i != j: adj[i].append(j) # Check connectivity visited = [False] * V q = deque() q.append(0) visited[0] = True while q: u = q.popleft() for v in adj[u]: if not visited[v]: visited[v] = True q.append(v) if not all(visited): print("No") return # Check for universal node has_universal = False for i in range(V): is_universal = True for j in range(V): if i == j: continue if E[i][j] != '1': is_universal = False break if is_universal: has_universal = True break if has_universal: if D >= 2: print("Yes") else: print("No") return # Check if bipartite color = [-1] * V is_bipartite = True for start in range(V): if color[start] == -1: color[start] = 0 q = deque() q.append(start) while q: u = q.popleft() for v in adj[u]: if color[v] == -1: color[v] = color[u] ^ 1 q.append(v) elif color[v] == color[u]: is_bipartite = False break if not is_bipartite: break if not is_bipartite: break if is_bipartite: print("No") return # If not bipartite and no universal node, check D >= 2 if D >= 2: print("Yes") else: print("No") if __name__ == "__main__": main()