結果

問題 No.2202 贅沢てりたまチキン
ユーザー komkompikomkompi
提出日時 2023-06-11 14:11:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 874 ms / 2,000 ms
コード長 1,676 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 95,372 KB
最終ジャッジ日時 2023-08-31 01:56:05
合計ジャッジ時間 9,758 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,400 KB
testcase_01 AC 70 ms
71,308 KB
testcase_02 AC 73 ms
71,436 KB
testcase_03 AC 71 ms
71,172 KB
testcase_04 AC 71 ms
71,604 KB
testcase_05 AC 70 ms
71,492 KB
testcase_06 AC 70 ms
71,388 KB
testcase_07 AC 71 ms
71,320 KB
testcase_08 AC 70 ms
71,524 KB
testcase_09 AC 70 ms
71,520 KB
testcase_10 AC 73 ms
80,708 KB
testcase_11 AC 68 ms
71,628 KB
testcase_12 AC 68 ms
71,316 KB
testcase_13 AC 72 ms
71,684 KB
testcase_14 AC 197 ms
87,976 KB
testcase_15 AC 196 ms
87,912 KB
testcase_16 AC 193 ms
88,000 KB
testcase_17 AC 206 ms
88,096 KB
testcase_18 AC 151 ms
83,152 KB
testcase_19 AC 150 ms
86,856 KB
testcase_20 AC 224 ms
88,516 KB
testcase_21 AC 223 ms
88,056 KB
testcase_22 AC 187 ms
77,704 KB
testcase_23 AC 321 ms
81,172 KB
testcase_24 AC 237 ms
79,468 KB
testcase_25 AC 874 ms
95,372 KB
testcase_26 AC 211 ms
88,064 KB
testcase_27 AC 199 ms
88,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

class UnionFind():
    # 初期化
    def __init__(self, n):
        self.par = [-1] * n
        self.rank = [0] * n
        self.siz = [1] * n

    # 根を求める
    def root(self, x):
        if self.par[x] == -1: return x # x が根の場合は x を返す
        else:
          self.par[x] = self.root(self.par[x]) # 経路圧縮
          return self.par[x]

    # x と y が同じグループに属するか (根が一致するか)
    def issame(self, x, y):
        return self.root(x) == self.root(y)

    # x を含むグループと y を含むグループを併合する
    def unite(self, x, y):
        # x 側と y 側の根を取得する
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry: return False # すでに同じグループのときは何もしない
        # union by rank
        if self.rank[rx] < self.rank[ry]: # ry 側の rank が小さくなるようにする
            rx, ry = ry, rx
        self.par[ry] = rx # ry を rx の子とする
        if self.rank[rx] == self.rank[ry]: # rx 側の rank を調整する
            self.rank[rx] += 1
        self.siz[rx] += self.siz[ry] # rx 側の siz を調整する
        return True
    
    # x を含む根付き木のサイズを求める
    def size(self, x):
        return self.siz[self.root(x)]


N,M=map(int,input().split())
uf=UnionFind(2*N)

for _ in range(M):
    A,B=map(int,input().split())
    A-=1
    B-=1
    r_A=2*N-A-1
    r_B=2*N-B-1
    
    uf.unite(A,r_B)
    uf.unite(B,r_A)

for i in range(N):
    if not uf.issame(i,2*N-i-1):
        print("No")
        exit()

print("Yes")
    



            
0