結果

問題 No.274 The Wall
ユーザー convexineqconvexineq
提出日時 2020-12-20 00:05:42
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,623 ms / 2,000 ms
コード長 1,481 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 81,688 KB
実行使用メモリ 77,480 KB
最終ジャッジ日時 2023-10-21 09:42:20
合計ジャッジ時間 6,834 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,548 KB
testcase_01 AC 39 ms
53,548 KB
testcase_02 AC 41 ms
53,548 KB
testcase_03 AC 649 ms
77,480 KB
testcase_04 AC 40 ms
53,548 KB
testcase_05 AC 39 ms
53,548 KB
testcase_06 AC 40 ms
53,548 KB
testcase_07 AC 39 ms
53,548 KB
testcase_08 AC 40 ms
53,548 KB
testcase_09 AC 40 ms
53,548 KB
testcase_10 AC 38 ms
53,548 KB
testcase_11 AC 1,623 ms
77,040 KB
testcase_12 AC 92 ms
72,988 KB
testcase_13 AC 54 ms
63,756 KB
testcase_14 AC 79 ms
70,636 KB
testcase_15 AC 110 ms
76,368 KB
testcase_16 AC 476 ms
77,304 KB
testcase_17 AC 438 ms
77,084 KB
testcase_18 AC 482 ms
77,100 KB
testcase_19 AC 139 ms
76,736 KB
testcase_20 AC 143 ms
76,684 KB
testcase_21 AC 143 ms
76,600 KB
testcase_22 AC 153 ms
76,708 KB
testcase_23 AC 151 ms
76,760 KB
testcase_24 AC 149 ms
76,668 KB
testcase_25 AC 139 ms
76,608 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,m = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(n)]

UF = UnionFind(2*n)
ok = 1
for i in range(n):
    li,ri = lr[i]
    lli,rri = m-1-ri,m-1-li
    for j in range(i+1,n):
        lj,rj = lr[j]
        c = 0
        if li <= rj and lj <= ri:
            if not UF.merge(i,j): ok = 0
            if not UF.merge(i+n,j+n): ok = 0
        if lli <= rj and lj <= rri:
            if not UF.merge(i+n,j): ok = 0
            if not UF.merge(i,j+n): ok = 0

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