def create_graph(N, connections): graph = [[] for _ in range(N)] for i, conn in enumerate(connections): M = conn[0] if M > 0: graph[i] = conn[1:] return graph def dfs(graph, v, visited, stack=None): visited[v] = True for neighbor in graph[v]: if not visited[neighbor - 1]: dfs(graph, neighbor - 1, visited, stack) if stack is not None: stack.append(v) def transpose_graph(graph): transposed = [[] for _ in range(len(graph))] for v in range(len(graph)): for neighbor in graph[v]: transposed[neighbor - 1].append(v + 1) return transposed def kosaraju(N, graph): visited = [False] * N stack = [] # Step 1: Fill vertices in stack according to their finishing times for i in range(N): if not visited[i]: dfs(graph, i, visited, stack) # Step 2: Transpose the graph transposed = transpose_graph(graph) # Step 3: Process all vertices in order defined by Stack visited = [False] * N while stack: v = stack.pop() if not visited[v]: component_stack = [] dfs(transposed, v, visited, component_stack) if len(component_stack) == N: return True return False def can_all_receive(N, connections): graph = create_graph(N, connections) return "Yes" if kosaraju(N, graph) else "No" # メイン関数 if __name__ == "__main__": import sys input = sys.stdin.read data = input().strip().split("\n") N = int(data[0].strip()) connections = [] for i in range(1, N + 1): connections.append(list(map(int, data[i].strip().split()))) result = can_all_receive(N, connections) print(result)