結果

問題 No.483 マッチ並べ
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-25 22:29:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,742 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-22 14:19:11
合計ジャッジ時間 3,521 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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)]


def touch(x, y, xx, yy):
    if x == xx:
        return True
    if y == yy:
        return True
    if x == yy:
        return True
    if y == xx:
        return True
    return False


N = int(input())
match = tuple(tuple(map(int, input().split())) for _ in range(N))
uf = UF_tree(N)
G = [[] for _ in range(N)]
cycle = 0
for i in range(N):
    r, c, rr, cc = match[i]
    for j in range(i+1, N):
        rrr, ccc, rrrr, cccc = match[j]
        if touch((r, c), (rr, cc), (rrr, ccc), (rrrr, cccc)) and uf.unite(i, j):
            G[i].append(j)

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

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

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