結果

問題 No.2277 Honest or Dishonest ?
ユーザー ntudantuda
提出日時 2023-04-23 10:36:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 576 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 168,128 KB
最終ジャッジ日時 2024-04-25 19:17:37
合計ジャッジ時間 15,894 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,492 KB
testcase_01 AC 36 ms
52,936 KB
testcase_02 AC 37 ms
53,012 KB
testcase_03 AC 360 ms
123,008 KB
testcase_04 AC 454 ms
147,484 KB
testcase_05 AC 157 ms
87,044 KB
testcase_06 AC 287 ms
111,036 KB
testcase_07 AC 263 ms
109,108 KB
testcase_08 AC 134 ms
85,788 KB
testcase_09 AC 283 ms
101,160 KB
testcase_10 AC 206 ms
98,672 KB
testcase_11 AC 131 ms
85,200 KB
testcase_12 AC 163 ms
87,832 KB
testcase_13 AC 341 ms
121,420 KB
testcase_14 AC 153 ms
89,256 KB
testcase_15 AC 143 ms
85,084 KB
testcase_16 AC 260 ms
108,688 KB
testcase_17 AC 167 ms
93,392 KB
testcase_18 AC 392 ms
119,860 KB
testcase_19 AC 388 ms
136,360 KB
testcase_20 AC 289 ms
107,404 KB
testcase_21 AC 235 ms
105,388 KB
testcase_22 AC 317 ms
128,056 KB
testcase_23 AC 242 ms
107,760 KB
testcase_24 AC 278 ms
113,436 KB
testcase_25 AC 263 ms
101,288 KB
testcase_26 AC 99 ms
78,668 KB
testcase_27 AC 165 ms
96,632 KB
testcase_28 AC 152 ms
86,208 KB
testcase_29 AC 196 ms
89,840 KB
testcase_30 AC 156 ms
91,160 KB
testcase_31 AC 240 ms
107,064 KB
testcase_32 AC 178 ms
88,532 KB
testcase_33 AC 416 ms
139,456 KB
testcase_34 AC 309 ms
122,204 KB
testcase_35 AC 96 ms
79,776 KB
testcase_36 AC 171 ms
96,452 KB
testcase_37 AC 279 ms
113,456 KB
testcase_38 AC 111 ms
81,840 KB
testcase_39 AC 140 ms
90,904 KB
testcase_40 AC 96 ms
78,388 KB
testcase_41 AC 272 ms
121,012 KB
testcase_42 AC 248 ms
107,676 KB
testcase_43 AC 305 ms
119,600 KB
testcase_44 AC 511 ms
137,008 KB
testcase_45 AC 576 ms
137,444 KB
testcase_46 AC 536 ms
168,128 KB
testcase_47 AC 514 ms
137,524 KB
testcase_48 AC 431 ms
127,864 KB
testcase_49 AC 326 ms
124,056 KB
testcase_50 AC 256 ms
108,860 KB
testcase_51 AC 377 ms
128,160 KB
testcase_52 AC 299 ms
117,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100050)

MOD = 998244353
N, Q = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(Q)]
E = [[] for _ in range(N)]
for a, b, c in ABC:
    E[a - 1].append((b - 1, c))
    E[b - 1].append((a - 1, c))
C = [-1] * N

def dfs(x):
    for y, c in E[x]:
        if C[y] == -1:
            C[y] = C[x] ^ c
            dfs(y)
        else:
            if C[y] != C[x] ^ c:
                print(0)
                exit()

cnt = 0
for i in range(N):
    if C[i] == -1:
        C[i] = 0
        cnt += 1
        dfs(i)
print(pow(2, cnt, MOD))
0