結果

問題 No.2134 $\sigma$-algebra over Finite Set
ユーザー だれだれ
提出日時 2022-11-06 20:21:15
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,082 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 81,656 KB
実行使用メモリ 85,984 KB
最終ジャッジ日時 2023-10-24 16:20:16
合計ジャッジ時間 4,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 37 ms
53,492 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 264 ms
78,964 KB
testcase_11 AC 264 ms
78,908 KB
testcase_12 AC 296 ms
79,508 KB
testcase_13 AC 301 ms
79,800 KB
testcase_14 AC 111 ms
76,480 KB
testcase_15 RE -
testcase_16 AC 103 ms
76,420 KB
testcase_17 AC 38 ms
53,492 KB
testcase_18 AC 38 ms
53,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    def find(self, x):
        if self.v[x] < 0:
            return x
        self.v[x] = find(self.v[x])
        return self.v[x]
    
    def merge(self, a, b):
        if a == b:
            return
        a = self.find(a)
        b = self.find(b)
        if self.v[a] > self.v[b]:
            a, b = b, a
        self.v[a] += self.v[b]
        self.v[b] = a
    
    def size(self):
        res = 0
        for i in range(self.n):
            if self.v[i] < 0:
                res += 1

        return res

n, m = map(int, input().split())
B = [(2 ** n - 1)] * n
A, A_c = [0] * n, [0] * n
for i in range(m):
    l, *a = map(int, input().split())
    for j in range(l):
        A[i] |= 1 << (a[j] - 1)
    A_c[i] = ~A[i]
    for j in range(n):
        if (A[i] >> j) & 1:
            B[j] &= A[i]
        else:
            B[j] &= A_c[i]

uf = UnionFind(n)
for i in range(n):
    for j in range(n):
        if B[i] == B[j]:
            uf.merge(i, j)
print(pow(2, uf.size(), 998244353))
0