結果

問題 No.483 マッチ並べ
ユーザー compass19compass19
提出日時 2017-02-16 23:35:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,009 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-12-30 01:32:21
合計ジャッジ時間 3,768 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
node2con = dict()
con_data = dict()
con_num = 0
clear = True
for _ in range(n):
    r0, c0, r1, c1 = map(int, input().split())
    if not clear: continue
    is_0 = (r0, c0) in node2con
    is_1 = (r1, c1) in node2con
    con0 = node2con[r0, c0] if is_0 else None
    con1 = node2con[r1, c1] if is_1 else None
    if is_0 and is_1:
        if con0 == con1:
            if con_data[con0]['roop']:
                clear = False
            else:
                con_data[con0]['roop'] = True
        else:
            for node in con_data[con1]['node']:
                node2con[node] = con0
    elif is_0 and not is_1:
        node2con[r1, c1] = con0
        con_data[con0]['node'].append((r0, c0))
    elif is_1 and not is_0:
        node2con[r0, c0] = con1
        con_data[con1]['node'].append((r1, c1))
    else:
        node2con[r0, c0] = node2con[r1, c1] = con_num
        con_data[con_num] = {'node': [(r0, c0), (r1, c1)], 'roop': False}
        con_num += 1
print(['NO', 'YES'][clear])
0