結果
| 問題 | 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 = 998244353
ans = 1
for i in range(q):
a,b,c = map(int,input().split())
a,b = a-1,b-1
e[a].append([b,c])
e[b].append([a,c])
vis = [0]*n
id = 0
def search(u,c,id):
dic = {}
dic[u] = c
vis[u] = id
q = [u]
ok = 1
while q:
now = q.pop()
c = dic[now]
for nex,nc in e[now]:
judge = nc^c
if nex in dic and dic[nex] != judge:
ok = 0
if vis[nex] == id:
continue
dic[nex] = judge
vis[nex] = id
q.append(nex)
return ok
for u in range(n):
if vis[u]:
continue
num = search(u,0,id+1) + search(u,1,id+2)
ans *= num
ans %= mod
id += 2
print(ans)