import sys from collections import deque def main(): V, D = map(int, sys.stdin.readline().split()) adj = [[] for _ in range(V)] for i in range(V): line = sys.stdin.readline().strip() for j in range(V): if line[j] == '1': adj[i].append(j) # Check if any node has degree 0 for i in range(V): if len(adj[i]) == 0: print("No") return # Check if the graph is connected 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 if the graph is bipartite is_bipartite = True color = [-1] * V for start in range(V): if color[start] == -1: q = deque() q.append(start) color[start] = 0 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 print("Yes") if __name__ == "__main__": main()