結果

問題 No.2277 Honest or Dishonest ?
ユーザー tonyu0tonyu0
提出日時 2023-04-21 23:13:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 84,416 KB
最終ジャッジ日時 2024-04-25 19:07:51
合計ジャッジ時間 20,954 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,256 KB
testcase_01 AC 38 ms
53,408 KB
testcase_02 AC 39 ms
52,892 KB
testcase_03 AC 447 ms
81,832 KB
testcase_04 AC 489 ms
83,036 KB
testcase_05 AC 191 ms
79,932 KB
testcase_06 AC 395 ms
80,144 KB
testcase_07 AC 397 ms
80,552 KB
testcase_08 AC 146 ms
79,736 KB
testcase_09 AC 392 ms
82,400 KB
testcase_10 AC 353 ms
80,516 KB
testcase_11 AC 270 ms
79,828 KB
testcase_12 AC 187 ms
77,716 KB
testcase_13 AC 432 ms
81,456 KB
testcase_14 AC 162 ms
77,780 KB
testcase_15 AC 181 ms
79,636 KB
testcase_16 AC 401 ms
80,868 KB
testcase_17 AC 307 ms
79,924 KB
testcase_18 AC 504 ms
83,724 KB
testcase_19 AC 492 ms
82,884 KB
testcase_20 AC 458 ms
82,840 KB
testcase_21 AC 345 ms
80,248 KB
testcase_22 AC 420 ms
82,024 KB
testcase_23 AC 344 ms
79,356 KB
testcase_24 AC 411 ms
82,600 KB
testcase_25 AC 378 ms
82,416 KB
testcase_26 AC 108 ms
79,264 KB
testcase_27 AC 290 ms
80,304 KB
testcase_28 AC 189 ms
79,964 KB
testcase_29 AC 258 ms
80,836 KB
testcase_30 AC 331 ms
79,352 KB
testcase_31 AC 414 ms
80,720 KB
testcase_32 AC 240 ms
80,496 KB
testcase_33 AC 495 ms
83,000 KB
testcase_34 AC 453 ms
81,748 KB
testcase_35 AC 105 ms
78,524 KB
testcase_36 AC 396 ms
80,764 KB
testcase_37 AC 398 ms
80,084 KB
testcase_38 AC 170 ms
77,516 KB
testcase_39 AC 254 ms
79,808 KB
testcase_40 AC 110 ms
78,176 KB
testcase_41 AC 458 ms
81,728 KB
testcase_42 AC 423 ms
80,256 KB
testcase_43 AC 497 ms
82,260 KB
testcase_44 AC 536 ms
84,416 KB
testcase_45 AC 535 ms
84,188 KB
testcase_46 AC 547 ms
84,168 KB
testcase_47 AC 521 ms
84,376 KB
testcase_48 AC 522 ms
83,640 KB
testcase_49 AC 517 ms
82,768 KB
testcase_50 AC 506 ms
81,816 KB
testcase_51 AC 521 ms
82,428 KB
testcase_52 AC 527 ms
82,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, q = map(int, input().split())

uf = [-1]*(2*n)


def root(a):
    if uf[a] < 0:
        return a
    uf[a] = root(uf[a])
    return uf[a]


def same(a, b):
    return root(a) == root(b)


def merge(a, b):
    if same(a, b):
        return
    a = root(a)
    b = root(b)
    if uf[b] < uf[a]:
        a, b = b, a
    uf[a] += uf[b]
    uf[b] = a


def sizeof(a):
    return -uf[a]


mod = 998244353
for _ in range(q):
    a, b, c = map(int, input().split())
    # 各人 2頂点用意する 
    # A B 0 のとき A0->B0, A1->B1に辺
    # A B 1 のとき A0->B1, A1->B0に辺
    # やって、A0とA1が同じ頂点で矛盾 (A0と仮定してA1が導かれるのが矛盾)
    a -= 1
    b -= 1
    if c == 0:
        merge(a, b)
        merge(a + n, b + n)
    else:
        merge(a, b + n)
        merge(a + n, b)

if same(a, a + n):
    print(0)
else:
    ch = [0] * (n * 2)
    ans = 1
    for i in range(n):
        r0 = root(i)
        r1 = root(i + n)
        if ch[r0] > 0 or ch[r1] > 0:
            continue
        ch[r0] = 1
        ch[r1] = 1
        ans = ans * 2 % mod
    print(ans)
0