結果

問題 No.483 マッチ並べ
ユーザー matsu7874matsu7874
提出日時 2017-02-10 23:25:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 868 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 8,732 KB
最終ジャッジ日時 2023-08-28 12:24:04
合計ジャッジ時間 3,066 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,616 KB
testcase_01 AC 19 ms
8,652 KB
testcase_02 AC 20 ms
8,688 KB
testcase_03 AC 19 ms
8,512 KB
testcase_04 AC 18 ms
8,556 KB
testcase_05 AC 18 ms
8,696 KB
testcase_06 AC 18 ms
8,540 KB
testcase_07 AC 18 ms
8,672 KB
testcase_08 AC 19 ms
8,700 KB
testcase_09 AC 18 ms
8,732 KB
testcase_10 AC 18 ms
8,588 KB
testcase_11 AC 18 ms
8,712 KB
testcase_12 AC 18 ms
8,560 KB
testcase_13 AC 18 ms
8,688 KB
testcase_14 AC 18 ms
8,676 KB
testcase_15 AC 18 ms
8,588 KB
testcase_16 AC 19 ms
8,512 KB
testcase_17 AC 19 ms
8,556 KB
testcase_18 AC 18 ms
8,544 KB
testcase_19 AC 19 ms
8,580 KB
testcase_20 AC 18 ms
8,596 KB
testcase_21 AC 18 ms
8,504 KB
testcase_22 AC 18 ms
8,648 KB
testcase_23 AC 18 ms
8,648 KB
testcase_24 AC 18 ms
8,552 KB
testcase_25 AC 20 ms
8,656 KB
testcase_26 AC 18 ms
8,516 KB
testcase_27 AC 19 ms
8,616 KB
testcase_28 AC 19 ms
8,624 KB
testcase_29 AC 19 ms
8,664 KB
testcase_30 AC 18 ms
8,616 KB
testcase_31 AC 19 ms
8,716 KB
testcase_32 AC 18 ms
8,660 KB
testcase_33 AC 19 ms
8,532 KB
testcase_34 AC 18 ms
8,696 KB
testcase_35 AC 19 ms
8,696 KB
testcase_36 AC 18 ms
8,716 KB
testcase_37 AC 19 ms
8,656 KB
testcase_38 AC 19 ms
8,564 KB
testcase_39 AC 19 ms
8,660 KB
testcase_40 AC 19 ms
8,588 KB
testcase_41 AC 19 ms
8,544 KB
testcase_42 AC 19 ms
8,588 KB
testcase_43 AC 19 ms
8,596 KB
testcase_44 AC 19 ms
8,624 KB
testcase_45 AC 18 ms
8,512 KB
testcase_46 AC 18 ms
8,560 KB
testcase_47 AC 18 ms
8,592 KB
testcase_48 AC 20 ms
8,684 KB
testcase_49 AC 18 ms
8,592 KB
testcase_50 AC 19 ms
8,584 KB
testcase_51 AC 19 ms
8,716 KB
testcase_52 AC 19 ms
8,696 KB
testcase_53 AC 18 ms
8,520 KB
testcase_54 AC 19 ms
8,660 KB
testcase_55 AC 20 ms
8,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0