結果

問題 No.2277 Honest or Dishonest ?
ユーザー square1001square1001
提出日時 2023-04-21 23:14:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 697 ms / 2,000 ms
コード長 481 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 40,576 KB
最終ジャッジ日時 2024-04-25 19:08:31
合計ジャッジ時間 23,118 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 26 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 573 ms
34,560 KB
testcase_04 AC 592 ms
35,840 KB
testcase_05 AC 230 ms
22,656 KB
testcase_06 AC 480 ms
30,336 KB
testcase_07 AC 381 ms
27,136 KB
testcase_08 AC 199 ms
22,016 KB
testcase_09 AC 339 ms
27,776 KB
testcase_10 AC 296 ms
22,656 KB
testcase_11 AC 144 ms
16,512 KB
testcase_12 AC 282 ms
21,760 KB
testcase_13 AC 555 ms
32,768 KB
testcase_14 AC 347 ms
24,320 KB
testcase_15 AC 192 ms
20,736 KB
testcase_16 AC 381 ms
26,752 KB
testcase_17 AC 180 ms
18,560 KB
testcase_18 AC 512 ms
34,432 KB
testcase_19 AC 545 ms
34,816 KB
testcase_20 AC 412 ms
29,824 KB
testcase_21 AC 407 ms
26,624 KB
testcase_22 AC 340 ms
26,880 KB
testcase_23 AC 553 ms
32,256 KB
testcase_24 AC 312 ms
25,600 KB
testcase_25 AC 402 ms
30,080 KB
testcase_26 AC 149 ms
19,584 KB
testcase_27 AC 272 ms
21,376 KB
testcase_28 AC 198 ms
20,736 KB
testcase_29 AC 308 ms
25,344 KB
testcase_30 AC 245 ms
20,992 KB
testcase_31 AC 409 ms
28,544 KB
testcase_32 AC 274 ms
24,064 KB
testcase_33 AC 536 ms
34,304 KB
testcase_34 AC 600 ms
35,712 KB
testcase_35 AC 99 ms
16,128 KB
testcase_36 AC 353 ms
26,240 KB
testcase_37 AC 577 ms
33,536 KB
testcase_38 AC 142 ms
16,000 KB
testcase_39 AC 185 ms
18,304 KB
testcase_40 AC 96 ms
15,360 KB
testcase_41 AC 638 ms
36,992 KB
testcase_42 AC 425 ms
29,312 KB
testcase_43 AC 666 ms
40,576 KB
testcase_44 AC 685 ms
40,448 KB
testcase_45 AC 669 ms
40,576 KB
testcase_46 AC 671 ms
40,448 KB
testcase_47 AC 663 ms
40,448 KB
testcase_48 AC 653 ms
40,448 KB
testcase_49 AC 662 ms
40,448 KB
testcase_50 AC 697 ms
40,576 KB
testcase_51 AC 680 ms
40,448 KB
testcase_52 AC 648 ms
40,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, q = map(int, input().split())
g = [ list() for i in range(n) ]
for i in range(q):
	a, b, c = map(int, input().split())
	a, b = a - 1, b - 1
	g[a].append((b, c))
	g[b].append((a, c))

col = [ -1 ] * n
answer = 1
for i in range(n):
	if col[i] == -1:
		v = [ i ]
		col[i] = 0
		while v:
			u = v.pop()
			for b, c in g[u]:
				if col[b] == -1:
					col[b] = col[u] ^ c
					v.append(b)
				elif col[b] != col[u] ^ c:
					answer = 0
		answer = answer * 2 % 998244353

print(answer)
0