結果

問題 No.2536 同値性と充足可能性
ユーザー mo124121mo124121
提出日時 2023-11-10 22:02:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,785 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 84,128 KB
最終ジャッジ日時 2023-11-10 22:02:53
合計ジャッジ時間 6,315 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,736 KB
testcase_01 AC 42 ms
55,736 KB
testcase_02 AC 42 ms
55,736 KB
testcase_03 AC 40 ms
55,736 KB
testcase_04 AC 39 ms
55,736 KB
testcase_05 AC 44 ms
55,736 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 42 ms
55,736 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 41 ms
55,736 KB
testcase_20 AC 79 ms
76,180 KB
testcase_21 AC 78 ms
76,176 KB
testcase_22 AC 78 ms
76,176 KB
testcase_23 AC 165 ms
76,460 KB
testcase_24 AC 176 ms
76,460 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 275 ms
84,128 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(2 * 10**3)

if sys.implementation.name == "pypy":
    import pypyjit

    pypyjit.set_param("max_unroll_recursion=-1")


from collections import defaultdict


input = lambda: sys.stdin.readline().rstrip()


class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parent_or_size = [-1] * N
        self.group_count = N

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

    def unite(self, x, y):
        root_x = self.root(x)
        root_y = self.root(y)
        if root_x == root_y:
            return
        if -self.parent_or_size[root_x] < -self.parent_or_size[root_y]:
            root_x, root_y = root_y, root_x
        self.parent_or_size[root_x] += self.parent_or_size[root_y]
        self.parent_or_size[root_y] = root_x
        self.group_count -= 1

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

    def size(self, x):
        return -self.parent_or_size[self.root(x)]

    def groups(self):
        ret = defaultdict(list)
        for i in range(self.N):
            ret[self.root(i)].append(i)
        return [group for group in ret.values()]


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

uf = UnionFind(N * 2)
for _ in range(M):
    i, s, j = input().split()
    i = int(i) - 1
    j = int(j) - 1
    if len(s) == 4:
        uf.unite(i, j)
        uf.unite(i + N, j + N)
    else:
        uf.unite(i, j + N)
        uf.unite(i + N, j)

for i in range(N):
    if uf.same(i, i + N):
        print("No")
        exit()

ans = [1]
for i in range(1, N):
    if uf.same(0, i):
        ans.append(i + 1)

print("Yes")
print(len(ans))
print(*ans)
0