結果

問題 No.1610 She Loves Me, She Loves Me Not, ...
ユーザー tassei903tassei903
提出日時 2021-07-21 21:45:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 78,116 KB
最終ジャッジ日時 2023-09-24 16:29:51
合計ジャッジ時間 5,937 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,612 KB
testcase_01 AC 102 ms
77,336 KB
testcase_02 AC 99 ms
71,692 KB
testcase_03 AC 93 ms
71,508 KB
testcase_04 AC 93 ms
71,788 KB
testcase_05 WA -
testcase_06 AC 120 ms
77,896 KB
testcase_07 AC 118 ms
77,720 KB
testcase_08 AC 111 ms
77,792 KB
testcase_09 WA -
testcase_10 AC 117 ms
77,424 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 103 ms
77,176 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 93 ms
71,632 KB
testcase_17 AC 92 ms
71,488 KB
testcase_18 WA -
testcase_19 AC 95 ms
71,796 KB
testcase_20 WA -
testcase_21 AC 93 ms
71,876 KB
testcase_22 WA -
testcase_23 AC 92 ms
71,772 KB
testcase_24 AC 90 ms
71,476 KB
testcase_25 AC 91 ms
71,760 KB
testcase_26 AC 92 ms
71,768 KB
testcase_27 WA -
testcase_28 AC 93 ms
71,664 KB
testcase_29 AC 92 ms
71,344 KB
testcase_30 AC 91 ms
71,848 KB
testcase_31 AC 91 ms
71,632 KB
testcase_32 AC 92 ms
71,344 KB
testcase_33 AC 91 ms
71,596 KB
testcase_34 AC 92 ms
71,616 KB
testcase_35 AC 93 ms
71,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes")
no = lambda :print("no");No = lambda :print("No")
#######################################################################

from collections import defaultdict

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 members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

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

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members

    def __str__(self):
        return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())


n, m = na()
uf = UnionFind(n)
for i in range(m):
    a,b = na()
    a-=1;b-=1;
    if uf.same(a,b):
        No()
        exit()
    uf.union(a, b)
ans = 0
for i in uf.roots():
    ans=(ans+uf.size(i)-1)%2

if ans:
    Yes()
else:
    No()
0