結果

問題 No.2277 Honest or Dishonest ?
ユーザー rlangevinrlangevin
提出日時 2023-04-21 21:48:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 92,200 KB
最終ジャッジ日時 2024-04-25 18:55:09
合計ジャッジ時間 10,279 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,356 KB
testcase_01 AC 41 ms
55,048 KB
testcase_02 AC 41 ms
54,336 KB
testcase_03 AC 194 ms
88,396 KB
testcase_04 AC 203 ms
90,352 KB
testcase_05 AC 129 ms
82,704 KB
testcase_06 AC 173 ms
86,160 KB
testcase_07 AC 150 ms
84,080 KB
testcase_08 AC 109 ms
83,260 KB
testcase_09 AC 163 ms
86,712 KB
testcase_10 AC 126 ms
82,332 KB
testcase_11 AC 90 ms
78,944 KB
testcase_12 AC 108 ms
80,628 KB
testcase_13 AC 191 ms
87,548 KB
testcase_14 AC 108 ms
80,864 KB
testcase_15 AC 120 ms
82,404 KB
testcase_16 AC 154 ms
84,204 KB
testcase_17 AC 103 ms
79,576 KB
testcase_18 AC 213 ms
90,024 KB
testcase_19 AC 214 ms
90,436 KB
testcase_20 AC 165 ms
85,844 KB
testcase_21 AC 139 ms
82,456 KB
testcase_22 AC 152 ms
85,316 KB
testcase_23 AC 165 ms
85,580 KB
testcase_24 AC 142 ms
84,984 KB
testcase_25 AC 174 ms
87,904 KB
testcase_26 AC 105 ms
82,444 KB
testcase_27 AC 98 ms
78,616 KB
testcase_28 AC 119 ms
82,292 KB
testcase_29 AC 151 ms
85,592 KB
testcase_30 AC 105 ms
79,944 KB
testcase_31 AC 131 ms
84,660 KB
testcase_32 AC 149 ms
84,880 KB
testcase_33 AC 206 ms
89,612 KB
testcase_34 AC 178 ms
88,616 KB
testcase_35 AC 90 ms
79,888 KB
testcase_36 AC 138 ms
84,168 KB
testcase_37 AC 169 ms
86,684 KB
testcase_38 AC 78 ms
78,136 KB
testcase_39 AC 91 ms
78,756 KB
testcase_40 AC 91 ms
79,536 KB
testcase_41 AC 209 ms
89,408 KB
testcase_42 AC 142 ms
85,320 KB
testcase_43 AC 212 ms
91,572 KB
testcase_44 AC 247 ms
91,612 KB
testcase_45 AC 231 ms
91,836 KB
testcase_46 AC 240 ms
92,200 KB
testcase_47 AC 238 ms
91,704 KB
testcase_48 AC 241 ms
91,640 KB
testcase_49 AC 225 ms
91,688 KB
testcase_50 AC 208 ms
91,568 KB
testcase_51 AC 202 ms
91,800 KB
testcase_52 AC 207 ms
91,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
from collections import *

N, Q = map(int, readline().split())
G = [[] for i in range(N)]
ans = 1
mod = 998244353
for i in range(Q):
    A, B, C = map(int, readline().split())
    A, B = A - 1, B - 1
    G[A].append((B, C))
    G[B].append((A, C))
    
D = deque()
dist = [-1] * N
for i in range(N):
    if dist[i] != -1:
        continue
    ans *= 2
    ans %= mod
    D.append(i)
    dist[i] = 0
    while D:
        u = D.popleft()
        for v, c in G[u]:
            if dist[v] == -1:
                dist[v] = (dist[u] + c) % 2
                D.append(v)
            else:
                if dist[v] != (dist[u] + c) % 2:
                    print(0)
                    exit()
print(ans)
    
0