結果

問題 No.488 四角関係
ユーザー 👑 yumechiyumechi
提出日時 2017-02-25 01:57:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 968 ms / 5,000 ms
コード長 650 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 112,684 KB
最終ジャッジ日時 2023-09-01 22:00:56
合計ジャッジ時間 6,337 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
93,880 KB
testcase_01 AC 213 ms
87,012 KB
testcase_02 AC 194 ms
92,124 KB
testcase_03 AC 138 ms
81,724 KB
testcase_04 AC 167 ms
85,056 KB
testcase_05 AC 276 ms
95,996 KB
testcase_06 AC 232 ms
112,684 KB
testcase_07 AC 591 ms
112,088 KB
testcase_08 AC 968 ms
102,716 KB
testcase_09 AC 92 ms
71,672 KB
testcase_10 AC 123 ms
80,020 KB
testcase_11 AC 105 ms
77,520 KB
testcase_12 AC 128 ms
78,352 KB
testcase_13 AC 124 ms
79,596 KB
testcase_14 AC 107 ms
77,616 KB
testcase_15 AC 99 ms
76,288 KB
testcase_16 AC 93 ms
71,508 KB
testcase_17 AC 93 ms
71,580 KB
testcase_18 AC 98 ms
75,972 KB
testcase_19 AC 103 ms
76,660 KB
testcase_20 AC 94 ms
71,628 KB
testcase_21 AC 93 ms
71,588 KB
testcase_22 AC 98 ms
75,972 KB
testcase_23 AC 99 ms
71,572 KB
testcase_24 AC 103 ms
76,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import itertools

def solve():
	n, m = map(int, input().split())
	node_pair = []
	
	for _ in range(m):
		a, b = map(int, input().split())
		node_pair.append([a, b])
	
	node_dict = defaultdict(list)
	for pair in node_pair:
		node_dict[pair[0]].append(pair[1])
		node_dict[pair[1]].append(pair[0])
	
	ans = 0
	for square in list(itertools.combinations(range(0, n+1), 4)):
		for idx in range(4):
			connection_count = 0
			for node in node_dict[square[idx]]:
				if node in square:
					connection_count += 1
			if connection_count != 2:
				break
		else:
			ans += 1
	print(ans)

if __name__=="__main__":
    solve()
0