結果

問題 No.483 マッチ並べ
ユーザー kohei2019kohei2019
提出日時 2022-07-27 00:50:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,000 KB
実行使用メモリ 56,472 KB
最終ジャッジ日時 2024-07-16 14:14:20
合計ジャッジ時間 4,055 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

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