結果

問題 No.2664 Prime Sum
ユーザー 👑 rin204rin204
提出日時 2024-03-08 21:03:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 77,276 KB
最終ジャッジ日時 2024-03-08 21:03:23
合計ジャッジ時間 3,369 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,460 KB
testcase_01 AC 32 ms
53,460 KB
testcase_02 AC 31 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 33 ms
53,460 KB
testcase_05 AC 53 ms
68,012 KB
testcase_06 AC 47 ms
63,756 KB
testcase_07 AC 40 ms
59,312 KB
testcase_08 AC 46 ms
63,756 KB
testcase_09 AC 49 ms
65,808 KB
testcase_10 AC 46 ms
63,756 KB
testcase_11 AC 34 ms
53,460 KB
testcase_12 AC 45 ms
61,696 KB
testcase_13 AC 49 ms
65,808 KB
testcase_14 AC 74 ms
77,276 KB
testcase_15 AC 75 ms
77,276 KB
testcase_16 AC 73 ms
77,276 KB
testcase_17 AC 43 ms
61,440 KB
testcase_18 AC 54 ms
65,808 KB
testcase_19 AC 55 ms
67,892 KB
testcase_20 AC 77 ms
76,752 KB
testcase_21 AC 80 ms
77,272 KB
testcase_22 AC 53 ms
63,756 KB
testcase_23 AC 81 ms
77,276 KB
testcase_24 AC 81 ms
77,276 KB
testcase_25 AC 79 ms
77,276 KB
testcase_26 AC 37 ms
53,460 KB
testcase_27 AC 40 ms
55,600 KB
testcase_28 AC 37 ms
53,460 KB
testcase_29 AC 39 ms
53,460 KB
testcase_30 AC 37 ms
53,460 KB
testcase_31 AC 38 ms
53,460 KB
testcase_32 AC 39 ms
53,460 KB
testcase_33 AC 40 ms
55,600 KB
testcase_34 AC 39 ms
53,460 KB
testcase_35 AC 45 ms
61,440 KB
testcase_36 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
        self.group_ = n

    def find(self, x):
        if self.par[x] < 0:
            return x
        lst = []
        while self.par[x] >= 0:
            lst.append(x)
            x = self.par[x]
        for y in lst:
            self.par[y] = x
        return x

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False

        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x
        self.group_ -= 1
        return True

    def size(self, x):
        return -self.par[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    @property
    def group(self):
        return self.group_


n, m = map(int, input().split())
UF = UnionFind(2 * n)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    UF.unite(a, b + n)
    UF.unite(a + n, b)

for i in range(n):
    if UF.same(i, i + n):
        print("No")
        exit()
print("Yes")
0