結果

問題 No.483 マッチ並べ
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-25 22:57:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,447 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-04-22 14:45:41
合計ジャッジ時間 4,705 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
13,952 KB
testcase_01 AC 50 ms
14,080 KB
testcase_02 AC 51 ms
14,208 KB
testcase_03 AC 51 ms
14,080 KB
testcase_04 AC 51 ms
14,080 KB
testcase_05 AC 50 ms
13,952 KB
testcase_06 AC 50 ms
13,952 KB
testcase_07 AC 49 ms
13,952 KB
testcase_08 AC 49 ms
13,952 KB
testcase_09 AC 51 ms
13,952 KB
testcase_10 AC 50 ms
14,208 KB
testcase_11 AC 49 ms
13,952 KB
testcase_12 AC 50 ms
13,952 KB
testcase_13 AC 51 ms
13,952 KB
testcase_14 AC 50 ms
13,952 KB
testcase_15 AC 50 ms
14,208 KB
testcase_16 AC 51 ms
13,952 KB
testcase_17 AC 49 ms
14,080 KB
testcase_18 AC 50 ms
13,952 KB
testcase_19 AC 50 ms
13,952 KB
testcase_20 AC 50 ms
14,080 KB
testcase_21 AC 50 ms
14,208 KB
testcase_22 AC 50 ms
14,080 KB
testcase_23 AC 51 ms
14,080 KB
testcase_24 AC 51 ms
14,080 KB
testcase_25 AC 51 ms
14,080 KB
testcase_26 AC 49 ms
13,952 KB
testcase_27 AC 51 ms
13,952 KB
testcase_28 AC 51 ms
13,952 KB
testcase_29 AC 49 ms
14,080 KB
testcase_30 AC 51 ms
14,080 KB
testcase_31 AC 51 ms
13,952 KB
testcase_32 AC 50 ms
13,952 KB
testcase_33 AC 50 ms
14,080 KB
testcase_34 AC 50 ms
14,080 KB
testcase_35 AC 50 ms
13,952 KB
testcase_36 AC 49 ms
14,080 KB
testcase_37 AC 50 ms
13,952 KB
testcase_38 AC 50 ms
13,952 KB
testcase_39 AC 50 ms
13,952 KB
testcase_40 AC 50 ms
14,080 KB
testcase_41 AC 50 ms
13,952 KB
testcase_42 AC 50 ms
14,080 KB
testcase_43 AC 52 ms
13,952 KB
testcase_44 AC 50 ms
14,080 KB
testcase_45 AC 50 ms
13,952 KB
testcase_46 AC 50 ms
14,080 KB
testcase_47 AC 50 ms
13,952 KB
testcase_48 AC 49 ms
14,080 KB
testcase_49 AC 50 ms
14,080 KB
testcase_50 AC 50 ms
14,080 KB
testcase_51 AC 51 ms
14,080 KB
testcase_52 AC 50 ms
13,952 KB
testcase_53 AC 52 ms
13,952 KB
testcase_54 AC 51 ms
14,080 KB
testcase_55 AC 50 ms
14,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        self.root[x] = self.find(self.root[x])
        return self.root[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return True

    def size(self, x):
        return -self.root[self.find(x)]


N = int(input())
U = 101 * 101
uf = UF_tree(U)
G = [[] for _ in range(U)]
for _ in range(N):
    x, y, xx, yy = map(int, input().split())
    s = x * 101 + y
    t = xx * 101 + yy
    uf.unite(s, t)
    G[s].append(t)
    G[t].append(s)

leader = {uf.find(i) for i in range(U)}
group = {i: [] for i in leader}
for i in range(U):
    group[uf.find(i)].append(i)

ok = True
for g in group.values():
    edge = 0
    for i in g:
        edge += len(G[i])
    edge //= 2
    if edge > len(g):
        ok = False

if ok:
    print("YES")
else:
    print("NO")
0