結果
| 問題 | No.488 四角関係 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-24 18:01:01 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,216 ms / 5,000 ms |
| コード長 | 1,403 bytes |
| 記録 | |
| コンパイル時間 | 735 ms |
| コンパイル使用メモリ | 85,888 KB |
| 実行使用メモリ | 82,176 KB |
| 最終ジャッジ日時 | 2026-06-24 18:01:16 |
| 合計ジャッジ時間 | 8,232 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
# 力づく全探索
from itertools import permutations
N, M = map(int, input().split())
G = [set() for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
G[a].add(b)
G[b].add(a)
ans = 0
for a in range(N):
for b in range(a+1,N):
for c in range(b+1,N):
for d in range(c+1,N):
flag3 = False
for p3 in permutations([a,b,c,d],3):
flag = True
for i in range(3):
pre = p3[(i-1) % 3]
post = p3[(i+1) % 3]
if pre not in G[p3[i]] or post not in G[p3[i]]:
flag = False
if flag:
flag3 = True
break
if flag3:
continue
flag4 = False
for p4 in permutations([a,b,c,d]):
flag = True
for i in range(4):
pre = p4[(i-1) % 4]
post = p4[(i+1) % 4]
if pre not in G[p4[i]] or post not in G[p4[i]]:
flag = False
if flag:
flag4 = True
break
if flag4:
ans += 1
print(ans)