結果

問題 No.2277 Honest or Dishonest ?
ユーザー titiatitia
提出日時 2023-04-23 02:19:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 751 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 40,576 KB
最終ジャッジ日時 2024-04-25 19:16:33
合計ジャッジ時間 23,979 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 618 ms
34,432 KB
testcase_04 AC 609 ms
35,840 KB
testcase_05 AC 248 ms
22,784 KB
testcase_06 AC 536 ms
30,464 KB
testcase_07 AC 428 ms
27,136 KB
testcase_08 AC 217 ms
22,016 KB
testcase_09 AC 398 ms
27,776 KB
testcase_10 AC 328 ms
22,656 KB
testcase_11 AC 157 ms
16,512 KB
testcase_12 AC 305 ms
21,760 KB
testcase_13 AC 602 ms
32,768 KB
testcase_14 AC 395 ms
24,448 KB
testcase_15 AC 215 ms
20,736 KB
testcase_16 AC 422 ms
26,752 KB
testcase_17 AC 211 ms
18,688 KB
testcase_18 AC 585 ms
34,432 KB
testcase_19 AC 591 ms
34,816 KB
testcase_20 AC 481 ms
29,696 KB
testcase_21 AC 448 ms
26,624 KB
testcase_22 AC 404 ms
26,880 KB
testcase_23 AC 506 ms
32,256 KB
testcase_24 AC 360 ms
25,600 KB
testcase_25 AC 453 ms
30,208 KB
testcase_26 AC 160 ms
19,584 KB
testcase_27 AC 250 ms
21,504 KB
testcase_28 AC 220 ms
20,736 KB
testcase_29 AC 321 ms
25,344 KB
testcase_30 AC 235 ms
21,120 KB
testcase_31 AC 372 ms
28,544 KB
testcase_32 AC 299 ms
23,936 KB
testcase_33 AC 590 ms
34,432 KB
testcase_34 AC 588 ms
35,584 KB
testcase_35 AC 106 ms
16,128 KB
testcase_36 AC 375 ms
26,240 KB
testcase_37 AC 523 ms
33,408 KB
testcase_38 AC 137 ms
15,872 KB
testcase_39 AC 191 ms
18,176 KB
testcase_40 AC 99 ms
15,360 KB
testcase_41 AC 605 ms
36,992 KB
testcase_42 AC 396 ms
29,312 KB
testcase_43 AC 645 ms
40,576 KB
testcase_44 AC 737 ms
40,576 KB
testcase_45 AC 734 ms
40,576 KB
testcase_46 AC 751 ms
40,576 KB
testcase_47 AC 735 ms
40,576 KB
testcase_48 AC 740 ms
40,576 KB
testcase_49 AC 647 ms
40,576 KB
testcase_50 AC 593 ms
40,448 KB
testcase_51 AC 593 ms
40,448 KB
testcase_52 AC 604 ms
40,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

E=[[] for i in range(N+1)]

for i in range(Q):
    x,y,c=map(int,input().split())
    E[x].append((y,c))
    E[y].append((x,c))

ANS=[-1]*(N+1)

mod=998244353


A=0

for i in range(1,N+1):
    if ANS[i]==-1:
        A+=1
        ANS[i]=0

        Q=[i]
        while Q:
            x=Q.pop()

            for to,c in E[x]:
                if c==0:
                    if ANS[to]==-1:
                        Q.append(to)
                        ANS[to]=ANS[x]
                    else:
                        if ANS[to]!=ANS[x]:
                            print(0)
                            exit()
                else:
                    if ANS[to]==-1:
                        Q.append(to)
                        ANS[to]=ANS[x]^1
                    else:
                        if ANS[to]==ANS[x]:
                            print(0)
                            exit()

print(pow(2,A,mod))
                        
0