結果

問題 No.1610 She Loves Me, She Loves Me Not, ...
ユーザー ysys
提出日時 2022-03-12 13:08:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,020 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 78,556 KB
最終ジャッジ日時 2023-10-15 01:46:42
合計ジャッジ時間 5,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,112 KB
testcase_01 AC 104 ms
76,140 KB
testcase_02 AC 76 ms
71,160 KB
testcase_03 AC 80 ms
71,256 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 143 ms
78,284 KB
testcase_07 AC 145 ms
78,136 KB
testcase_08 AC 147 ms
77,840 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 146 ms
78,020 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 88 ms
75,300 KB
testcase_16 WA -
testcase_17 AC 90 ms
75,420 KB
testcase_18 AC 89 ms
75,436 KB
testcase_19 AC 88 ms
75,660 KB
testcase_20 WA -
testcase_21 AC 87 ms
75,476 KB
testcase_22 WA -
testcase_23 AC 79 ms
71,368 KB
testcase_24 AC 78 ms
71,344 KB
testcase_25 AC 78 ms
71,548 KB
testcase_26 AC 77 ms
71,472 KB
testcase_27 AC 78 ms
71,136 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

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

for i in range(M):
  a, b = map(int, input().split())
  a, b = a - 1, b - 1
  uf.union(a, b)


ans = 0
for p in uf.roots():
  ans += uf.size(p) - 1



if ans % 2 == 1:
  print('Yes')
else:
  print('No')
0