結果

問題 No.2277 Honest or Dishonest ?
ユーザー minimumminimum
提出日時 2023-04-21 21:48:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 100,304 KB
最終ジャッジ日時 2023-08-08 00:50:16
合計ジャッジ時間 17,523 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,500 KB
testcase_01 AC 93 ms
71,348 KB
testcase_02 AC 95 ms
71,504 KB
testcase_03 AC 350 ms
92,612 KB
testcase_04 AC 363 ms
97,336 KB
testcase_05 AC 234 ms
90,168 KB
testcase_06 AC 258 ms
87,656 KB
testcase_07 AC 252 ms
88,652 KB
testcase_08 AC 220 ms
89,860 KB
testcase_09 AC 286 ms
92,796 KB
testcase_10 AC 217 ms
84,272 KB
testcase_11 AC 179 ms
81,148 KB
testcase_12 AC 185 ms
81,264 KB
testcase_13 AC 298 ms
90,892 KB
testcase_14 AC 191 ms
83,536 KB
testcase_15 AC 225 ms
88,116 KB
testcase_16 AC 245 ms
88,244 KB
testcase_17 AC 188 ms
83,280 KB
testcase_18 AC 338 ms
96,648 KB
testcase_19 AC 358 ms
96,632 KB
testcase_20 AC 295 ms
91,868 KB
testcase_21 AC 236 ms
86,444 KB
testcase_22 AC 266 ms
90,016 KB
testcase_23 AC 270 ms
88,900 KB
testcase_24 AC 277 ms
89,780 KB
testcase_25 AC 304 ms
94,924 KB
testcase_26 AC 192 ms
87,392 KB
testcase_27 AC 198 ms
82,828 KB
testcase_28 AC 218 ms
87,804 KB
testcase_29 AC 260 ms
91,688 KB
testcase_30 AC 207 ms
84,640 KB
testcase_31 AC 266 ms
89,476 KB
testcase_32 AC 247 ms
90,700 KB
testcase_33 AC 335 ms
95,576 KB
testcase_34 AC 335 ms
93,676 KB
testcase_35 AC 176 ms
84,280 KB
testcase_36 AC 254 ms
88,388 KB
testcase_37 AC 282 ms
90,048 KB
testcase_38 AC 162 ms
79,320 KB
testcase_39 AC 185 ms
82,156 KB
testcase_40 AC 175 ms
82,892 KB
testcase_41 AC 341 ms
94,044 KB
testcase_42 AC 278 ms
90,548 KB
testcase_43 AC 399 ms
99,800 KB
testcase_44 AC 404 ms
100,180 KB
testcase_45 AC 412 ms
99,964 KB
testcase_46 AC 404 ms
99,948 KB
testcase_47 AC 411 ms
99,860 KB
testcase_48 AC 411 ms
99,628 KB
testcase_49 AC 413 ms
100,300 KB
testcase_50 AC 418 ms
100,072 KB
testcase_51 AC 399 ms
99,648 KB
testcase_52 AC 406 ms
100,304 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