結果

問題 No.2202 贅沢てりたまチキン
ユーザー Mat_hMat_h
提出日時 2023-02-03 21:48:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 760 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 94,364 KB
最終ジャッジ日時 2023-09-15 17:31:27
合計ジャッジ時間 6,171 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,276 KB
testcase_01 AC 73 ms
71,328 KB
testcase_02 AC 69 ms
71,164 KB
testcase_03 AC 70 ms
71,380 KB
testcase_04 AC 68 ms
71,340 KB
testcase_05 AC 69 ms
71,312 KB
testcase_06 AC 67 ms
71,320 KB
testcase_07 AC 69 ms
71,536 KB
testcase_08 AC 68 ms
71,328 KB
testcase_09 AC 68 ms
71,024 KB
testcase_10 AC 74 ms
80,596 KB
testcase_11 AC 69 ms
71,548 KB
testcase_12 AC 69 ms
71,356 KB
testcase_13 AC 69 ms
71,428 KB
testcase_14 AC 239 ms
87,776 KB
testcase_15 AC 197 ms
87,844 KB
testcase_16 AC 189 ms
88,156 KB
testcase_17 AC 196 ms
88,248 KB
testcase_18 AC 149 ms
83,344 KB
testcase_19 AC 151 ms
86,800 KB
testcase_20 AC 224 ms
88,192 KB
testcase_21 AC 223 ms
88,244 KB
testcase_22 AC 187 ms
77,352 KB
testcase_23 AC 319 ms
80,436 KB
testcase_24 AC 236 ms
79,564 KB
testcase_25 AC 760 ms
94,364 KB
testcase_26 AC 206 ms
87,884 KB
testcase_27 AC 193 ms
87,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]
    
    def issame(self, x, y):
        return self.root(x) == self.root(y)
    
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return False
        if self.rank[rx] < self.rank[ry]:
            rx, ry = ry, rx
        self.par[ry] = rx
        if self.rank[rx] == self.rank[ry]:
            self.rank[rx] += 1
        self.siz[rx] += self.siz[ry]
        return True
    
    def size(self, x):
        return self.siz[self.root(x)]
def main():
    n,m=map(int,input().split())
    tree=UnionFind(n*2+2)
    for _ in range(m):
        a,b=map(int,input().split())
        tree.unite(a*2,b*2+1)
        tree.unite(b*2,a*2+1)
    for i in range(1,n+1):
        if tree.issame(i*2,i*2+1):
            continue
        else:
            print("No")
            exit()
    print("Yes")    
    
main()

0