結果
| 問題 | No.2277 Honest or Dishonest ? | 
| コンテスト | |
| ユーザー |  miscalc | 
| 提出日時 | 2023-04-21 11:11:56 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,206 ms / 2,000 ms | 
| コード長 | 625 bytes | 
| コンパイル時間 | 804 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 43,520 KB | 
| 最終ジャッジ日時 | 2024-11-08 06:22:46 | 
| 合計ジャッジ時間 | 33,907 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 50 | 
ソースコード
from collections import deque
MOD = 998244353
n, q = map(int, input().split())
g = [[] for i in range(n)]
for _ in range(q):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  g[a].append([b, c])
  g[b].append([a, c])
ans = 1
colors = [-1] * n
for sv in range(n):
  if colors[sv] != -1:
    continue
  ans = ans * 2 % MOD
  colors[sv] = 0
  deq = deque()
  deq.append(sv)
  while len(deq) > 0:
    v = deq.popleft()
    for nv, d in g[v]:
      new_color = colors[v] ^ d
      if colors[nv] == -1:
        colors[nv] = new_color
        deq.append(nv)
      elif colors[nv] != new_color:
        ans *= 0
print(ans)
            
            
            
        