結果

問題 No.408 五輪ピック
ユーザー lam6er
提出日時 2025-04-16 00:56:50
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,121 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 96,308 KB
最終ジャッジ日時 2025-04-16 00:58:25
合計ジャッジ時間 9,363 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 MLE * 9 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    adj = [set() for _ in range(N + 1)]
    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

    # Precompute S as a set for faster lookups
    S_set = S

    for x in S:
        # Iterate through all a adjacent to x (excluding 1 and x)
        for a in adj[x]:
            if a == 1 or a == x:
                continue
            # Iterate through all b adjacent to a (excluding 1, x, a)
            for b in adj[a]:
                if b == 1 or b == x or b == a:
                    continue
                # Iterate through all y adjacent to b (check if y is in S and not x, a, b)
                for y in adj[b]:
                    if y in S_set and y not in {x, a, b}:
                        print("YES")
                        return

    print("NO")

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