結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー |
|
提出日時 | 2023-04-21 22:58:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 559 ms / 2,000 ms |
コード長 | 834 bytes |
コンパイル時間 | 358 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 120,064 KB |
最終ジャッジ日時 | 2024-11-08 06:40:37 |
合計ジャッジ時間 | 20,559 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
n,q = map(int,input().split())e = [[] for i in range(n)]mod = 998244353ans = 1for i in range(q):a,b,c = map(int,input().split())a,b = a-1,b-1e[a].append([b,c])e[b].append([a,c])vis = [0]*nid = 0def search(u,c,id):dic = {}dic[u] = cvis[u] = idq = [u]ok = 1while q:now = q.pop()c = dic[now]for nex,nc in e[now]:judge = nc^cif nex in dic and dic[nex] != judge:ok = 0if vis[nex] == id:continuedic[nex] = judgevis[nex] = idq.append(nex)return okfor u in range(n):if vis[u]:continuenum = search(u,0,id+1) + search(u,1,id+2)ans *= numans %= modid += 2print(ans)