結果
| 問題 | No.488 四角関係 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-25 01:29:49 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,049 bytes |
| 記録 | |
| コンパイル時間 | 799 ms |
| コンパイル使用メモリ | 85,248 KB |
| 実行使用メモリ | 1,001,856 KB |
| 最終ジャッジ日時 | 2026-06-06 13:27:15 |
| 合計ジャッジ時間 | 11,650 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 8 MLE * 1 -- * 13 |
ソースコード
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 = []
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:
tpair.sort()
squares.append(tuple(tpair))
else:
pairs.append(tpair)
squares = set(squares)
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()