import sys from collections import deque def main(): sys.setrecursionlimit(1 << 25) V, D = map(int, sys.stdin.readline().split()) E = [] for _ in range(V): line = sys.stdin.readline().strip() row = [int(c) for c in line] E.append(row) # Step 1: Check all nodes have at least one outgoing edge for i in range(V): if sum(E[i]) == 0: print("No") return # Step 2: Check if the graph is connected (BFS) visited = [False]*V q = deque() q.append(0) visited[0] = True while q: u = q.popleft() for v in range(V): if E[u][v] and not visited[v]: visited[v] = True q.append(v) if not all(visited): print("No") return # Step 3: Check if the graph is bipartite (BFS) color = [-1]*V is_bipartite = True 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 range(V): if E[u][v]: 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") else: print("Yes") if __name__ == "__main__": main()