結果

問題 No.2910 単体ホモロジー入門
ユーザー H3PO4
提出日時 2024-10-04 21:31:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-04 21:31:46
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

N, M = map(int, input().split())
arr = [[False] * N for _ in range(N)]
for _ in range(M):
    i, j = map(int, input().split())
    arr[i][j] = True
    arr[j][i] = True

V = set(map(int, input().split()))
for b in range(1 << N):
    t = []
    for i in range(N):
        if b & (1 << i):
            t.append(i)
    if set(t) == V:
        continue
    for u in itertools.permutations(t):
        if not u:
            continue
        if len(u) <= 2:
            continue
        flag = True
        if not arr[u[0]][u[-1]]:
            flag = False
        for i in range(1, len(u)):
            if not arr[u[i - 1]][u[i]]:
                flag = False
        if flag:
            print("Yes")
            exit()
print("No")
0