結果

問題 No.488 四角関係
ユーザー 👑 yumechiyumechi
提出日時 2017-02-25 01:37:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,070 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 109,564 KB
最終ジャッジ日時 2023-09-01 21:54:53
合計ジャッジ時間 10,153 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
79,928 KB
testcase_01 AC 380 ms
86,264 KB
testcase_02 AC 217 ms
82,628 KB
testcase_03 AC 214 ms
82,264 KB
testcase_04 AC 241 ms
82,760 KB
testcase_05 AC 393 ms
88,020 KB
testcase_06 AC 163 ms
80,092 KB
testcase_07 AC 1,157 ms
109,564 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from collections import defaultdict
import copy

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])
	
	squares = set()	
	for i in range(n):
		pairs = deque()
		pairs.append([i])
		while len(pairs) > 0:
			pair = pairs.popleft()
			connect_nodes = node_dict[pair[-1]]
			for node in connect_nodes:
				if node not in pair:
					tpair = copy.deepcopy(pair)
					tpair.append(node)
					if len(tpair) == 4:
						if tpair[0] in node_dict[tpair[-1]]:
							tpair.sort()
							squares.add(tuple(tpair))
					else:
						pairs.append(tpair)
	ans = 0
	for square in squares:
		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