結果

問題 No.408 五輪ピック
ユーザー rpy3cpp
提出日時 2016-08-05 23:12:48
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 937 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 33,860 KB
最終ジャッジ日時 2024-11-07 01:12:10
合計ジャッジ時間 6,056 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, M = map(int, input().split())
    Es = [set() for i in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        Es[a].add(b)
        Es[b].add(a)
    return N, M, Es

def solve(N, M, Es):
    '''
    Es に頂点0を含む長さ5 の単純閉路が存在するか否かを返す。
    '''
    d1 = Es[0]
    d2 = set()
    for d1i in d1:
        d2 |= Es[d1i]
    bss = [d1 & Esb for Esb in Es]
    for c in d2:
        for d in Es[c]:
            if d in d2:
                if is_valid(c, d, bss):
                    return True
    return False

def is_valid(c, d, bss):
    bs = bss[c]
    es = bss[d]
    if not (bs - {d}):
        return False
    if not (es - {c}):
        return False
    if len((bs | es) - {c} - {d}) < 2:
        return False    
    return True

N, M, Es = read_data()
if solve(N, M, Es):
    print("YES")
else:
    print("NO")
0