結果

問題 No.488 四角関係
ユーザー daku9640daku9640
提出日時 2018-08-30 21:19:08
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 695 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-09-13 20:35:36
合計ジャッジ時間 1,952 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from itertools import combinations
def solve():
    n, m = map(int, input().split())
    if n < 4:
        return 0
    node = defaultdict(set)
    for _ in range(m):
        a, b = map(int, input().split())
        node[a].add(b)
        node[b].add(a)
    ans = set()
    for i in range(n - 1):
        for j in range(i + 1, n):
            if j in node[i]:
                continue
            sn = node[i] & node[j] - {i, j}
            if len(sn) < 2:
                continue
            for a, b in combinations(tuple(sn), 2):
                if a not in node[b]:
                    ans.add(frozenset([i, j, a, b]))
    return len(ans)
print(solve())
0