結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 31 ms
10,880 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 31 ms
10,880 KB
testcase_12 AC 32 ms
10,880 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 32 ms
10,880 KB
testcase_17 AC 32 ms
10,752 KB
testcase_18 AC 31 ms
10,880 KB
testcase_19 WA -
testcase_20 AC 31 ms
10,752 KB
testcase_21 AC 31 ms
10,880 KB
testcase_22 AC 31 ms
10,880 KB
testcase_23 AC 32 ms
10,880 KB
testcase_24 AC 31 ms
10,880 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 35 ms
10,880 KB
testcase_28 AC 35 ms
11,008 KB
testcase_29 AC 34 ms
10,880 KB
testcase_30 WA -
testcase_31 AC 35 ms
10,880 KB
testcase_32 AC 35 ms
10,752 KB
testcase_33 AC 32 ms
10,880 KB
testcase_34 AC 31 ms
11,008 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 33 ms
11,008 KB
testcase_41 AC 35 ms
10,880 KB
testcase_42 AC 35 ms
10,880 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 31 ms
10,880 KB
testcase_54 AC 31 ms
10,752 KB
testcase_55 AC 31 ms
10,880 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)]


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)):
            G[i].append(j)
            uf.unite(i, 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