結果

問題 No.483 マッチ並べ
ユーザー maspy
提出日時 2020-03-24 14:15:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-12-31 14:58:26
合計ジャッジ時間 3,931 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

# !/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter

N = int(readline())
m = map(int, read().split())
L = 112
graph = [[] for _ in range(L * L)]
for a, b, c, d in zip(m, m, m, m):
    x = L * a + b
    y = L * c + d
    graph[x].append(y)
    graph[y].append(x)

comp = [0] * (L * L)
ng = False
for i in range(L * L):
    if comp[i]:
        continue
    comp[i] = i
    Nv = 1
    Ne = 0
    stack = [i]
    while stack:
        v = stack.pop()
        for w in graph[v]:
            Ne += 1
            if comp[w]:
                continue
            comp[w] = i
            Nv += 1
            stack.append(w)
    Ne //= 2
    if Ne > Nv:
        ng = True
        break

print('NO' if ng else 'YES')
0