結果

問題 No.2277 Honest or Dishonest ?
ユーザー 👑 Kazun
提出日時 2023-04-21 22:03:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 887 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 101,760 KB
最終ジャッジ日時 2024-11-08 06:31:39
合計ジャッジ時間 12,908 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N,Q=map(int,input().split())

    Data=[[] for _ in range(N+1)]
    for i in range(Q):
        A,B,C=map(int,input().split())
        Data[A].append((B,C))
        Data[B].append((A,C))

    T=[0]*(N+1)
    ans=1; Mod=998244353
    for x in range(1,N+1):
        if T[x]:
            continue

        E=[set([x]), set()]
        S=[x]; T[x]=1
        while S:
            y=S.pop()
            mode=0 if y in E[0] else 1
            for b,c in Data[y]:
                if (b in E[0]) or (b in E[1]):
                    if b not in E[mode^c]:
                        return 0
                else:
                    S.append(b)
                    E[mode^c].add(b)
                    T[b]=1
        ans*=2
        ans%=Mod
    return ans

#==================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write

print(solve())
0