結果
問題 |
No.408 五輪ピック
|
ユーザー |
|
提出日時 | 2016-08-05 23:35:26 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 989 bytes |
コンパイル時間 | 438 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 33,728 KB |
最終ジャッジ日時 | 2024-11-07 04:25:38 |
合計ジャッジ時間 | 6,044 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 WA * 2 |
ソースコード
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 の単純閉路が存在するか否かを返す。 ''' if N < 5: return False if M < 5: return False 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] - {d} es = bss[d] - {c} if not bs: return False if not es: return False if len(bs | es) < 2: return False return True N, M, Es = read_data() if solve(N, M, Es): print("YES") else: print("NO")