結果

問題 No.2277 Honest or Dishonest ?
ユーザー tamatotamato
提出日時 2023-04-21 21:44:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 82,684 KB
実行使用メモリ 97,456 KB
最終ジャッジ日時 2024-04-25 18:53:13
合計ジャッジ時間 10,315 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,240 KB
testcase_01 AC 38 ms
54,624 KB
testcase_02 AC 39 ms
54,308 KB
testcase_03 AC 175 ms
91,164 KB
testcase_04 AC 210 ms
95,696 KB
testcase_05 AC 130 ms
84,704 KB
testcase_06 AC 151 ms
87,460 KB
testcase_07 AC 137 ms
85,748 KB
testcase_08 AC 117 ms
83,948 KB
testcase_09 AC 165 ms
88,776 KB
testcase_10 AC 116 ms
83,076 KB
testcase_11 AC 87 ms
79,272 KB
testcase_12 AC 99 ms
80,728 KB
testcase_13 AC 164 ms
89,508 KB
testcase_14 AC 97 ms
80,872 KB
testcase_15 AC 120 ms
83,656 KB
testcase_16 AC 139 ms
85,796 KB
testcase_17 AC 100 ms
79,840 KB
testcase_18 AC 193 ms
93,904 KB
testcase_19 AC 193 ms
93,880 KB
testcase_20 AC 158 ms
89,848 KB
testcase_21 AC 121 ms
82,548 KB
testcase_22 AC 138 ms
87,288 KB
testcase_23 AC 145 ms
85,884 KB
testcase_24 AC 139 ms
86,864 KB
testcase_25 AC 153 ms
89,756 KB
testcase_26 AC 97 ms
82,584 KB
testcase_27 AC 108 ms
81,640 KB
testcase_28 AC 111 ms
82,980 KB
testcase_29 AC 130 ms
85,588 KB
testcase_30 AC 123 ms
82,756 KB
testcase_31 AC 169 ms
88,560 KB
testcase_32 AC 143 ms
85,120 KB
testcase_33 AC 228 ms
93,300 KB
testcase_34 AC 220 ms
91,912 KB
testcase_35 AC 90 ms
80,116 KB
testcase_36 AC 160 ms
87,176 KB
testcase_37 AC 172 ms
87,688 KB
testcase_38 AC 84 ms
78,508 KB
testcase_39 AC 101 ms
78,672 KB
testcase_40 AC 91 ms
79,792 KB
testcase_41 AC 225 ms
93,076 KB
testcase_42 AC 178 ms
89,308 KB
testcase_43 AC 229 ms
96,248 KB
testcase_44 AC 247 ms
96,320 KB
testcase_45 AC 242 ms
97,420 KB
testcase_46 AC 232 ms
97,456 KB
testcase_47 AC 236 ms
97,376 KB
testcase_48 AC 269 ms
97,384 KB
testcase_49 AC 264 ms
97,336 KB
testcase_50 AC 239 ms
96,880 KB
testcase_51 AC 244 ms
96,772 KB
testcase_52 AC 245 ms
95,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
mod = 998244353
from collections import deque

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

ans = 1
seen = [-1] * (N + 1)
for v0 in range(1, N + 1):
    if seen[v0] != -1:
        continue
    seen[v0] = 0
    que = deque()
    que.append(v0)
    ok = 1
    V = []
    while que:
        v = que.popleft()
        V.append(v)
        for u, c in adj[v]:
            if seen[u] == -1:
                if c == 0:
                    seen[u] = seen[v]
                else:
                    seen[u] = seen[v] ^ 1
                que.append(u)
            else:
                if c == 0:
                    if seen[u] != seen[v]:
                        ok = 0
                else:
                    if seen[u] == seen[v]:
                        ok = 0
    if ok:
        ans = (ans * 2) % mod
    else:
        ans = 0
print(ans)
0