結果

問題 No.2277 Honest or Dishonest ?
ユーザー ニックネーム
提出日時 2023-04-21 21:57:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 797 ms / 2,000 ms
コード長 457 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 40,448 KB
最終ジャッジ日時 2024-11-08 06:32:08
合計ジャッジ時間 27,393 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

n,q = map(int,input().split())
adj = [[] for _ in range(n)]; mod = 998244353
for _ in range(q):
    a,b,c = map(int,input().split())
    adj[a-1].append((b-1,c)); adj[b-1].append((a-1,c))
ans = 1; f = [-1]*n
for i in range(n):
    if f[i]!=-1: continue
    ans = ans*2%mod; f[i] = 0; st = [i]
    while st:
        p = st.pop()
        for v,c in adj[p]:
            if f[v]==-1: f[v] = f[p]^c; st.append(v)
            elif f[v]!=f[p]^c: ans = 0
print(ans)
0