結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:52:08 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,261 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 81,876 KB |
実行使用メモリ | 176,268 KB |
最終ジャッジ日時 | 2025-04-16 00:54:08 |
合計ジャッジ時間 | 8,594 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 WA * 1 MLE * 6 |
ソースコード
import sys from sys import stdin def main(): sys.setrecursionlimit(1 << 25) N, M = map(int, stdin.readline().split()) adj = [set() for _ in range(N + 1)] for _ in range(M): u, v = map(int, stdin.readline().split()) adj[u].add(v) adj[v].add(u) S = adj[1] if len(S) < 2: print("NO") return # Precompute neighbors_in_S for each node neighbors_in_S = [set() for _ in range(N + 1)] for node in S: for neighbor in adj[node]: neighbors_in_S[neighbor].add(node) for a in S: two_step = set() # Iterate over neighbors of a, excluding 1 and a itself for b in adj[a]: if b == 1 or b == a: continue # Iterate over neighbors of b, excluding 1, a, and b for c in adj[b]: if c == 1 or c == a or c == b: continue two_step.add(c) # Check each c in two_step for c in two_step: s = neighbors_in_S[c] if not s: continue if a not in s or len(s) >= 2: print("YES") return print("NO") if __name__ == "__main__": main()