結果

問題 No.2277 Honest or Dishonest ?
ユーザー ntudantuda
提出日時 2023-04-23 00:15:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 934 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 88,832 KB
最終ジャッジ日時 2024-04-25 19:15:25
合計ジャッジ時間 7,659 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,724 KB
testcase_01 AC 38 ms
53,304 KB
testcase_02 AC 35 ms
53,744 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 147 ms
86,452 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 103 ms
80,548 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 85 ms
79,672 KB
testcase_31 AC 105 ms
83,428 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 147 ms
86,072 KB
testcase_35 WA -
testcase_36 AC 116 ms
81,244 KB
testcase_37 AC 135 ms
87,240 KB
testcase_38 AC 74 ms
77,068 KB
testcase_39 AC 83 ms
78,916 KB
testcase_40 WA -
testcase_41 AC 140 ms
87,408 KB
testcase_42 AC 122 ms
83,524 KB
testcase_43 AC 133 ms
88,076 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 137 ms
88,244 KB
testcase_50 AC 145 ms
88,184 KB
testcase_51 AC 144 ms
88,024 KB
testcase_52 AC 146 ms
88,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def find(x):
    if P[x] == x: return x
    else:
        P[x] = find(P[x]) #経路圧縮
        return P[x]
        # return find(P[x]) #経路圧縮なし

def same(x,y):
    return find(x) == find(y)

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y: return 0
    if x > y: x,y = y,x
    P[y] = x

def group_count():
    for i in range(N):
        P[i] = find(i)
    return len(set(P))

MOD = 998244353
N,Q = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(Q)]

P = [i for i in range(N)]
state = [-1] * N
for a,b,c in ABC:
    a -= 1
    b -= 1
    unite(a,b)
    if state[a] == -1 and state[b] == -1:
        state[a] = 0
        state[b] = 0 ^ c
    elif state[a] == -1:
        state[a] = state[b] ^ c
    elif state[b] == -1:
        state[b] = state[a] ^ c
    else:
        if state[a] != state[b] ^ c:
            print(0)
            exit()

x = group_count()
print(pow(2,x,MOD))
0