結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:59:55 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,121 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 81,884 KB |
実行使用メモリ | 96,944 KB |
最終ジャッジ日時 | 2025-04-16 01:01:24 |
合計ジャッジ時間 | 8,871 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 MLE * 10 -- * 4 |
ソースコード
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()