結果

問題 No.488 四角関係
ユーザー rpy3cpp
提出日時 2017-03-26 00:50:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-07-06 06:17:19
合計ジャッジ時間 1,914 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, M = map(int, input().split())
    Es = [set() for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        Es[a].add(b)
        Es[b].add(a)
    return N, M, Es

def solve(N, M, Es):
    pool = set()
    for a in range(N):
        for b in Es[a]:
            for c in Es[b]:
                if c == a:
                    continue
                if a in Es[c]:
                    continue
                for d in Es[c]:
                    if d == b:
                        continue
                    if a not in Es[d]:
                        continue
                    if b in Es[d]:
                        continue
                    pool.add(tuple(sorted([a, b, c, d])))
    return len(pool)

N, M, Es = read_data()
print(solve(N, M, Es))
0