結果

問題 No.488 四角関係
コンテスト
ユーザー daku9640
提出日時 2018-08-30 23:02:30
言語 Python3
(3.15.2 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 275 ms / 5,000 ms
+ 414µs
コード長 652 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 55 ms
コンパイル使用メモリ 14,720 KB
実行使用メモリ 34,908 KB
最終ジャッジ日時 2026-11-05 23:55:57
合計ジャッジ時間 3,281 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 k, v in node.items():
        if len(v) < 2:
            continue
        for a, b in combinations(tuple(v), 2):
            if a in node[b]:
                continue
            for c in node[a] & node[b] - {k}:
                if k not in node[c]:
                    ans.add(frozenset([a, b, c, k]))
    return len(ans)
print(solve())
0