結果

問題 No.2277 Honest or Dishonest ?
ユーザー minimumminimum
提出日時 2023-04-21 21:48:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 99,780 KB
最終ジャッジ日時 2024-04-25 18:54:05
合計ジャッジ時間 12,643 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,056 KB
testcase_01 AC 38 ms
54,228 KB
testcase_02 AC 40 ms
55,372 KB
testcase_03 AC 229 ms
90,828 KB
testcase_04 AC 279 ms
96,324 KB
testcase_05 AC 174 ms
88,716 KB
testcase_06 AC 190 ms
88,064 KB
testcase_07 AC 188 ms
87,100 KB
testcase_08 AC 158 ms
89,108 KB
testcase_09 AC 209 ms
91,768 KB
testcase_10 AC 149 ms
83,808 KB
testcase_11 AC 117 ms
81,024 KB
testcase_12 AC 121 ms
79,168 KB
testcase_13 AC 213 ms
89,308 KB
testcase_14 AC 122 ms
80,892 KB
testcase_15 AC 152 ms
86,924 KB
testcase_16 AC 165 ms
86,400 KB
testcase_17 AC 121 ms
81,636 KB
testcase_18 AC 247 ms
95,692 KB
testcase_19 AC 256 ms
95,448 KB
testcase_20 AC 203 ms
90,540 KB
testcase_21 AC 154 ms
84,100 KB
testcase_22 AC 174 ms
88,224 KB
testcase_23 AC 179 ms
86,864 KB
testcase_24 AC 186 ms
88,172 KB
testcase_25 AC 226 ms
94,176 KB
testcase_26 AC 129 ms
85,952 KB
testcase_27 AC 136 ms
80,872 KB
testcase_28 AC 153 ms
86,488 KB
testcase_29 AC 186 ms
90,456 KB
testcase_30 AC 140 ms
82,336 KB
testcase_31 AC 185 ms
87,588 KB
testcase_32 AC 175 ms
89,136 KB
testcase_33 AC 243 ms
94,192 KB
testcase_34 AC 244 ms
92,540 KB
testcase_35 AC 114 ms
82,508 KB
testcase_36 AC 173 ms
86,644 KB
testcase_37 AC 197 ms
88,052 KB
testcase_38 AC 103 ms
78,180 KB
testcase_39 AC 118 ms
80,332 KB
testcase_40 AC 115 ms
81,892 KB
testcase_41 AC 243 ms
93,140 KB
testcase_42 AC 199 ms
89,216 KB
testcase_43 AC 303 ms
99,588 KB
testcase_44 AC 316 ms
99,408 KB
testcase_45 AC 319 ms
99,292 KB
testcase_46 AC 329 ms
99,308 KB
testcase_47 AC 309 ms
99,472 KB
testcase_48 AC 309 ms
99,416 KB
testcase_49 AC 326 ms
99,572 KB
testcase_50 AC 312 ms
99,448 KB
testcase_51 AC 326 ms
99,348 KB
testcase_52 AC 324 ms
99,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

MOD = 998244353

N, Q = map(int, input().split())
edges = [[] for _ in range(N)]
edges_c = [[] for _ in range(N)]
for _ in range(Q):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
    edges_c[a].append(c)
    edges_c[b].append(c)


dist = [-1] * N
ans = 1
for i in range(N):
    if dist[i] != -1:
        continue
    ans *= 2
    ans %= MOD
    dist[i] = 0
    dq = deque()
    dq.append(i)
    while dq:
        now = dq.popleft()
        for j in range(len(edges[now])):
            nxt = edges[now][j]
            cost = dist[now] + edges_c[now][j]
            if dist[nxt] == -1:
                dist[nxt] = cost
                if edges_c[now][j] == 0:
                    dq.appendleft(nxt)
                else:
                    dq.append(nxt)
            else:
                if (dist[nxt] - cost) % 2:
                    ans = 0
print(ans)
0