結果

問題 No.483 マッチ並べ
ユーザー convexineqconvexineq
提出日時 2021-02-14 23:14:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 76,232 KB
最終ジャッジ日時 2023-09-29 17:06:13
合計ジャッジ時間 7,259 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
76,140 KB
testcase_01 AC 69 ms
75,144 KB
testcase_02 AC 71 ms
76,148 KB
testcase_03 AC 72 ms
76,224 KB
testcase_04 AC 75 ms
75,944 KB
testcase_05 AC 73 ms
76,132 KB
testcase_06 AC 69 ms
74,952 KB
testcase_07 AC 71 ms
76,036 KB
testcase_08 AC 71 ms
75,948 KB
testcase_09 AC 72 ms
75,920 KB
testcase_10 AC 72 ms
76,088 KB
testcase_11 AC 71 ms
74,928 KB
testcase_12 AC 71 ms
75,248 KB
testcase_13 AC 73 ms
75,904 KB
testcase_14 AC 74 ms
76,152 KB
testcase_15 AC 74 ms
76,084 KB
testcase_16 AC 73 ms
75,944 KB
testcase_17 AC 74 ms
75,992 KB
testcase_18 AC 71 ms
76,072 KB
testcase_19 AC 72 ms
76,124 KB
testcase_20 AC 70 ms
75,148 KB
testcase_21 AC 71 ms
75,008 KB
testcase_22 AC 71 ms
74,972 KB
testcase_23 AC 71 ms
74,976 KB
testcase_24 AC 72 ms
74,972 KB
testcase_25 AC 75 ms
76,140 KB
testcase_26 AC 75 ms
75,952 KB
testcase_27 AC 74 ms
76,092 KB
testcase_28 AC 75 ms
76,036 KB
testcase_29 AC 75 ms
75,896 KB
testcase_30 AC 75 ms
76,208 KB
testcase_31 AC 74 ms
76,088 KB
testcase_32 AC 75 ms
76,152 KB
testcase_33 AC 74 ms
76,228 KB
testcase_34 AC 75 ms
76,124 KB
testcase_35 AC 74 ms
75,944 KB
testcase_36 AC 73 ms
76,044 KB
testcase_37 AC 74 ms
76,152 KB
testcase_38 AC 74 ms
76,192 KB
testcase_39 AC 72 ms
76,100 KB
testcase_40 AC 71 ms
75,072 KB
testcase_41 AC 73 ms
75,932 KB
testcase_42 AC 74 ms
75,908 KB
testcase_43 AC 76 ms
76,048 KB
testcase_44 AC 72 ms
76,176 KB
testcase_45 AC 73 ms
76,096 KB
testcase_46 AC 73 ms
75,988 KB
testcase_47 AC 74 ms
76,072 KB
testcase_48 AC 73 ms
76,028 KB
testcase_49 AC 72 ms
76,072 KB
testcase_50 AC 72 ms
75,992 KB
testcase_51 AC 73 ms
76,004 KB
testcase_52 AC 73 ms
76,232 KB
testcase_53 AC 73 ms
75,916 KB
testcase_54 AC 80 ms
76,036 KB
testcase_55 AC 75 ms
75,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す.
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]
        

n = int(input())
M = 112
UF = UnionFind(M*M)
res = [0]*(M*M)
for _ in range(n):
    a,b,c,d = map(int,input().split())
    v = (a-1)*M+b-1
    w = (c-1)*M+d-1
    if not UF.merge(v,w):
        res[v] += 1
for i in range(M*M):
    r = UF.root(i)
    if r != i:
        res[r] += res[i]
    if res[r] >= 2:
        print("NO")
        exit()
print("YES")
0