結果

問題 No.2277 Honest or Dishonest ?
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-04-21 22:58:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 834 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 119,832 KB
最終ジャッジ日時 2024-04-25 19:05:10
合計ジャッジ時間 15,887 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,696 KB
testcase_01 AC 36 ms
53,684 KB
testcase_02 AC 36 ms
53,484 KB
testcase_03 AC 352 ms
114,252 KB
testcase_04 AC 390 ms
114,080 KB
testcase_05 AC 186 ms
87,792 KB
testcase_06 AC 290 ms
103,372 KB
testcase_07 AC 241 ms
96,944 KB
testcase_08 AC 168 ms
86,148 KB
testcase_09 AC 260 ms
101,972 KB
testcase_10 AC 187 ms
91,980 KB
testcase_11 AC 132 ms
83,460 KB
testcase_12 AC 152 ms
86,732 KB
testcase_13 AC 317 ms
105,588 KB
testcase_14 AC 146 ms
87,928 KB
testcase_15 AC 158 ms
85,500 KB
testcase_16 AC 243 ms
97,816 KB
testcase_17 AC 134 ms
86,096 KB
testcase_18 AC 324 ms
116,048 KB
testcase_19 AC 356 ms
114,060 KB
testcase_20 AC 292 ms
105,580 KB
testcase_21 AC 219 ms
95,080 KB
testcase_22 AC 240 ms
101,808 KB
testcase_23 AC 301 ms
100,140 KB
testcase_24 AC 245 ms
100,100 KB
testcase_25 AC 278 ms
102,360 KB
testcase_26 AC 147 ms
83,484 KB
testcase_27 AC 168 ms
89,036 KB
testcase_28 AC 164 ms
85,492 KB
testcase_29 AC 202 ms
89,932 KB
testcase_30 AC 165 ms
91,068 KB
testcase_31 AC 277 ms
103,680 KB
testcase_32 AC 189 ms
89,004 KB
testcase_33 AC 343 ms
112,188 KB
testcase_34 AC 387 ms
112,716 KB
testcase_35 AC 120 ms
80,844 KB
testcase_36 AC 232 ms
100,060 KB
testcase_37 AC 323 ms
104,800 KB
testcase_38 AC 107 ms
77,764 KB
testcase_39 AC 138 ms
83,528 KB
testcase_40 AC 119 ms
80,348 KB
testcase_41 AC 392 ms
119,752 KB
testcase_42 AC 287 ms
103,312 KB
testcase_43 AC 429 ms
117,388 KB
testcase_44 AC 428 ms
119,832 KB
testcase_45 AC 425 ms
118,896 KB
testcase_46 AC 429 ms
116,824 KB
testcase_47 AC 421 ms
117,204 KB
testcase_48 AC 434 ms
119,680 KB
testcase_49 AC 416 ms
117,228 KB
testcase_50 AC 420 ms
119,748 KB
testcase_51 AC 425 ms
118,040 KB
testcase_52 AC 425 ms
118,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
        
0