結果

問題 No.408 五輪ピック
ユーザー lam6er
提出日時 2025-03-31 17:34:24
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 933 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 96,352 KB
最終ジャッジ日時 2025-03-31 17:35:07
合計ジャッジ時間 9,635 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 MLE * 14 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from sys import stdin
from collections import defaultdict

def main():
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    M = int(input[idx])
    idx += 1

    if N < 5:
        print("NO")
        return

    adj = defaultdict(set)
    for _ in range(M):
        u = int(input[idx])
        idx += 1
        v = int(input[idx])
        idx += 1
        adj[u].add(v)
        adj[v].add(u)

    S = adj[1]
    if not S:
        print("NO")
        return

    # Check for possible 5-cycle
    for a in S:
        for b in adj[a]:
            if b == 1:
                continue
            for c in adj[b]:
                if c == 1 or c == a:
                    continue
                for d in adj[c]:
                    if d in S and d not in {a, b, c}:
                        print("YES")
                        return

    print("NO")

if __name__ == "__main__":
    main()
0