結果

問題 No.2134 $\sigma$-algebra over Finite Set
ユーザー shobonvipshobonvip
提出日時 2022-11-26 00:18:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 77,216 KB
最終ジャッジ日時 2024-04-10 05:03:55
合計ジャッジ時間 2,477 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,616 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 36 ms
52,412 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 38 ms
53,156 KB
testcase_09 AC 38 ms
53,620 KB
testcase_10 AC 99 ms
76,792 KB
testcase_11 AC 88 ms
76,588 KB
testcase_12 AC 102 ms
76,984 KB
testcase_13 AC 127 ms
76,776 KB
testcase_14 AC 80 ms
76,588 KB
testcase_15 AC 78 ms
76,364 KB
testcase_16 AC 77 ms
76,624 KB
testcase_17 AC 37 ms
53,548 KB
testcase_18 AC 36 ms
52,460 KB
権限があれば一括ダウンロードができます

ソースコード

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

n,m = map(int,input().split())
uf = UnionFind(n)

for i in range(m):
	l = list(map(int,input().split()))
	v = [0] * n

	for j in range(1, l[0]+1):
		v[l[j] - 1] = 1
	
	a = -1
	b = -1
	for j in range(n):
		if v[j] == 1:
			if a >= 0:
				uf.union(a, j)
			a = j
		else:
			if b >= 0:
				uf.union(b, j)
			b = j

mod = 998244353
ans = pow(2, n+1, mod)
inv2 = pow(2, mod-2, mod)
for i in range(n):
	if uf.parents[i] < 0:
		ans *= inv2
		ans %= mod

print(ans)
0