# 閉路検出 def find_cycles_with_paths(graph): def dfs(node, parent): visited[node] = True stack.append(node) for neighbour in graph[node]: if not visited[neighbour]: if dfs(neighbour, node): return True elif parent != neighbour: cycle_start_index = stack.index(neighbour) cycles.append(stack[cycle_start_index:]) return True stack.pop() return False visited = [False] * len(graph) cycles = [] stack = [] for node in range(len(graph)): if not visited[node]: if dfs(node, -1): break return cycles # input N,M = map(int,input().split()) G = [[] for i in range(N)] for i in range(M): A, B = map(int, input().split()) G[A].append(B) G[B].append(A) V = map(int,input().split()) # 閉路の集合 ans_list = [set(V) for V in find_cycles_with_paths(G)] # 一致しないものが存在するときはYes if set(V) not in ans_list: ans = 'Yes' else: ans = 'No' print(ans)