結果
問題 | No.483 マッチ並べ |
ユーザー | matsu7874 |
提出日時 | 2017-02-10 23:25:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 868 bytes |
コンパイル時間 | 452 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-12-29 11:14:39 |
合計ジャッジ時間 | 3,587 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 53 |
ソースコード
import collections n = int(input()) node_idx = 0 nodes = {} g = [] cnt = [] for i in range(n): a,b,c,d = map(int, input().split()) if not (a,b) in nodes: nodes[(a,b)] = node_idx node_idx += 1 g.append([]) cnt.append(0) if not (c,d) in nodes: nodes[(c,d)] = node_idx node_idx += 1 g.append([]) cnt.append(0) g[nodes[(a,b)]].append(nodes[(c,d)]) g[nodes[(c,d)]].append(nodes[(a,b)]) cnt[nodes[(a,b)]] += 1 cnt[nodes[(c,d)]] += 1 remove = True size_g = len(g) while remove: remove = False for i in range(node_idx): if cnt[i] == 1: cnt[i] -= 1 cnt[g[i][0]] -= 1 g[g[i][0]].remove(i) g[i] = [] remove = True for i in range(node_idx): if len(g[i])>2: print("NO") exit() print("YES")