結果

問題 No.2277 Honest or Dishonest ?
ユーザー 👑 KazunKazun
提出日時 2023-04-21 22:03:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 887 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,972 KB
実行使用メモリ 102,088 KB
最終ジャッジ日時 2024-04-25 18:57:05
合計ジャッジ時間 9,685 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,876 KB
testcase_01 AC 34 ms
52,748 KB
testcase_02 AC 34 ms
54,304 KB
testcase_03 AC 191 ms
93,832 KB
testcase_04 AC 211 ms
98,556 KB
testcase_05 AC 123 ms
83,960 KB
testcase_06 AC 154 ms
88,552 KB
testcase_07 AC 135 ms
87,524 KB
testcase_08 AC 116 ms
83,592 KB
testcase_09 AC 146 ms
89,852 KB
testcase_10 AC 114 ms
83,456 KB
testcase_11 AC 90 ms
78,740 KB
testcase_12 AC 95 ms
80,248 KB
testcase_13 AC 168 ms
91,364 KB
testcase_14 AC 99 ms
80,676 KB
testcase_15 AC 122 ms
83,156 KB
testcase_16 AC 139 ms
86,960 KB
testcase_17 AC 94 ms
79,544 KB
testcase_18 AC 205 ms
96,692 KB
testcase_19 AC 213 ms
97,680 KB
testcase_20 AC 173 ms
92,096 KB
testcase_21 AC 130 ms
82,552 KB
testcase_22 AC 156 ms
89,596 KB
testcase_23 AC 141 ms
85,280 KB
testcase_24 AC 150 ms
87,968 KB
testcase_25 AC 186 ms
91,080 KB
testcase_26 AC 104 ms
82,232 KB
testcase_27 AC 100 ms
81,008 KB
testcase_28 AC 140 ms
83,160 KB
testcase_29 AC 155 ms
85,424 KB
testcase_30 AC 96 ms
79,480 KB
testcase_31 AC 118 ms
83,824 KB
testcase_32 AC 164 ms
85,100 KB
testcase_33 AC 212 ms
96,284 KB
testcase_34 AC 195 ms
94,212 KB
testcase_35 AC 101 ms
79,704 KB
testcase_36 AC 135 ms
86,080 KB
testcase_37 AC 145 ms
86,080 KB
testcase_38 AC 76 ms
77,596 KB
testcase_39 AC 90 ms
78,504 KB
testcase_40 AC 107 ms
79,660 KB
testcase_41 AC 187 ms
93,420 KB
testcase_42 AC 134 ms
84,824 KB
testcase_43 AC 207 ms
97,108 KB
testcase_44 AC 251 ms
101,480 KB
testcase_45 AC 256 ms
101,272 KB
testcase_46 AC 259 ms
101,000 KB
testcase_47 AC 245 ms
102,088 KB
testcase_48 AC 245 ms
101,792 KB
testcase_49 AC 217 ms
99,088 KB
testcase_50 AC 176 ms
93,736 KB
testcase_51 AC 170 ms
91,936 KB
testcase_52 AC 169 ms
93,724 KB
権限があれば一括ダウンロードができます

ソースコード

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