結果

問題 No.483 マッチ並べ
コンテスト
ユーザー kohei2019
提出日時 2022-07-27 00:50:46
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 37 ms / 2,000 ms
+ 173µs
コード長 791 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 84 ms
コンパイル使用メモリ 64,512 KB
実行使用メモリ 53,776 KB
最終ジャッジ日時 2026-10-20 06:16:40
合計ジャッジ時間 4,432 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import collections
N = int(input())
lsg = collections.defaultdict(list)
node = []
for i in range(N):
    r1,c1,r2,c2 = map(int,input().split())
    lsg[(r1,c1)].append((r2,c2))
    lsg[(r2,c2)].append((r1,c1))
    node.append((r1,c1))
    node.append((r2,c2))
used = collections.defaultdict(lambda :False)
ans = True
for x,y in node:
    if used[(x,y)]:
        continue
    d = collections.deque([(x,y)])
    roop = 0
    while d:
        x,y = d.pop()
        if used[(x,y)]:
            continue
        used[(x,y)] = True
        c = 0
        for xn,yn in lsg[(x,y)]:
            if used[(xn,yn)]:
                c += 1
                continue
            d.append((xn,yn))
        if c >= 2:
            roop += c-1
    if roop >= 2:
        ans = False
print('YES' if ans else 'NO')
0