結果

問題 No.2277 Honest or Dishonest ?
ユーザー ntudantuda
提出日時 2023-04-23 10:40:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,696 KB
実行使用メモリ 104,036 KB
最終ジャッジ日時 2024-04-25 19:17:00
合計ジャッジ時間 10,741 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,924 KB
testcase_01 AC 38 ms
53,792 KB
testcase_02 AC 38 ms
54,792 KB
testcase_03 AC 213 ms
98,184 KB
testcase_04 AC 219 ms
99,580 KB
testcase_05 AC 142 ms
87,264 KB
testcase_06 AC 181 ms
93,964 KB
testcase_07 AC 160 ms
91,712 KB
testcase_08 AC 144 ms
86,084 KB
testcase_09 AC 180 ms
92,260 KB
testcase_10 AC 141 ms
87,444 KB
testcase_11 AC 108 ms
80,264 KB
testcase_12 AC 126 ms
85,536 KB
testcase_13 AC 181 ms
91,904 KB
testcase_14 AC 140 ms
88,900 KB
testcase_15 AC 137 ms
85,572 KB
testcase_16 AC 165 ms
91,104 KB
testcase_17 AC 122 ms
84,164 KB
testcase_18 AC 213 ms
98,644 KB
testcase_19 AC 225 ms
99,276 KB
testcase_20 AC 183 ms
94,180 KB
testcase_21 AC 147 ms
88,252 KB
testcase_22 AC 155 ms
91,632 KB
testcase_23 AC 180 ms
95,200 KB
testcase_24 AC 164 ms
90,788 KB
testcase_25 AC 176 ms
94,352 KB
testcase_26 AC 122 ms
83,512 KB
testcase_27 AC 119 ms
81,280 KB
testcase_28 AC 133 ms
85,516 KB
testcase_29 AC 176 ms
89,928 KB
testcase_30 AC 130 ms
82,320 KB
testcase_31 AC 177 ms
91,880 KB
testcase_32 AC 152 ms
88,816 KB
testcase_33 AC 208 ms
98,440 KB
testcase_34 AC 189 ms
98,936 KB
testcase_35 AC 104 ms
81,216 KB
testcase_36 AC 137 ms
84,784 KB
testcase_37 AC 191 ms
96,356 KB
testcase_38 AC 97 ms
79,364 KB
testcase_39 AC 105 ms
79,652 KB
testcase_40 AC 108 ms
80,744 KB
testcase_41 AC 205 ms
99,980 KB
testcase_42 AC 157 ms
92,780 KB
testcase_43 AC 221 ms
100,524 KB
testcase_44 AC 258 ms
104,036 KB
testcase_45 AC 257 ms
103,648 KB
testcase_46 AC 242 ms
103,576 KB
testcase_47 AC 244 ms
103,768 KB
testcase_48 AC 247 ms
103,736 KB
testcase_49 AC 221 ms
100,328 KB
testcase_50 AC 203 ms
100,536 KB
testcase_51 AC 196 ms
100,600 KB
testcase_52 AC 204 ms
100,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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 bfs(x):
    q = deque([x])
    while q:
        x = q.popleft()
        for y, c in E[x]:
            if C[y] == -1:
                C[y] = C[x] ^ c
                q.append(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
        bfs(i)

print(pow(2, cnt, MOD))
0