結果

問題 No.2910 単体ホモロジー入門
ユーザー Taka
提出日時 2023-11-19 11:45:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,104 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 82,004 KB
実行使用メモリ 52,608 KB
最終ジャッジ日時 2024-09-26 06:15:32
合計ジャッジ時間 3,837 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

# 閉路検出
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)
0