結果

問題 No.2277 Honest or Dishonest ?
ユーザー shobonvipshobonvip
提出日時 2023-04-21 21:47:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 91,104 KB
最終ジャッジ日時 2024-04-25 18:54:53
合計ジャッジ時間 17,534 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,012 KB
testcase_01 AC 35 ms
52,716 KB
testcase_02 AC 33 ms
53,764 KB
testcase_03 AC 356 ms
84,432 KB
testcase_04 AC 405 ms
88,312 KB
testcase_05 AC 167 ms
85,200 KB
testcase_06 AC 329 ms
82,488 KB
testcase_07 AC 337 ms
83,144 KB
testcase_08 AC 142 ms
86,304 KB
testcase_09 AC 309 ms
87,016 KB
testcase_10 AC 294 ms
80,732 KB
testcase_11 AC 241 ms
79,772 KB
testcase_12 AC 181 ms
77,812 KB
testcase_13 AC 382 ms
84,152 KB
testcase_14 AC 132 ms
77,784 KB
testcase_15 AC 147 ms
83,748 KB
testcase_16 AC 311 ms
82,388 KB
testcase_17 AC 253 ms
80,304 KB
testcase_18 AC 368 ms
88,816 KB
testcase_19 AC 389 ms
88,080 KB
testcase_20 AC 355 ms
85,436 KB
testcase_21 AC 254 ms
80,336 KB
testcase_22 AC 325 ms
83,820 KB
testcase_23 AC 287 ms
80,236 KB
testcase_24 AC 335 ms
84,796 KB
testcase_25 AC 289 ms
87,716 KB
testcase_26 AC 104 ms
84,868 KB
testcase_27 AC 231 ms
79,300 KB
testcase_28 AC 159 ms
82,700 KB
testcase_29 AC 227 ms
86,040 KB
testcase_30 AC 320 ms
81,560 KB
testcase_31 AC 355 ms
83,432 KB
testcase_32 AC 208 ms
85,228 KB
testcase_33 AC 378 ms
87,904 KB
testcase_34 AC 382 ms
85,460 KB
testcase_35 AC 90 ms
81,248 KB
testcase_36 AC 373 ms
83,676 KB
testcase_37 AC 355 ms
81,848 KB
testcase_38 AC 144 ms
77,564 KB
testcase_39 AC 211 ms
78,684 KB
testcase_40 AC 98 ms
80,412 KB
testcase_41 AC 402 ms
86,096 KB
testcase_42 AC 353 ms
83,920 KB
testcase_43 AC 442 ms
90,152 KB
testcase_44 AC 434 ms
89,684 KB
testcase_45 AC 397 ms
89,384 KB
testcase_46 AC 417 ms
90,432 KB
testcase_47 AC 415 ms
89,884 KB
testcase_48 AC 408 ms
89,364 KB
testcase_49 AC 432 ms
91,104 KB
testcase_50 AC 432 ms
90,496 KB
testcase_51 AC 440 ms
90,844 KB
testcase_52 AC 451 ms
90,464 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


mod = 998244353
n, q = map(int,input().split())
ikeru = [[] for i in range(2*n)]
uf = UnionFind(2*n)
for i in range(q):
	a, b, c = map(int,input().split())
	a-=1; b-=1
	if c == 0:
		uf.union(a, b)
		uf.union(n+a, n+b)
	else:
		uf.union(a, n+b)
		uf.union(n+a, b)

ans = 1
for i in range(n):
	if uf.find(i) == uf.find(i+n):
		ans = 0
	if uf.find(i) == i:
		ans *= 2
		ans %= mod

print(ans)
0