結果

問題 No.803 Very Limited Xor Subset
ユーザー maspymaspy
提出日時 2020-04-14 22:22:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 44,104 KB
最終ジャッジ日時 2024-04-09 18:15:50
合計ジャッジ時間 29,043 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 524 ms
43,948 KB
testcase_01 AC 523 ms
43,980 KB
testcase_02 AC 528 ms
43,820 KB
testcase_03 AC 527 ms
43,952 KB
testcase_04 AC 531 ms
43,692 KB
testcase_05 AC 526 ms
43,816 KB
testcase_06 AC 531 ms
43,972 KB
testcase_07 AC 527 ms
43,828 KB
testcase_08 AC 529 ms
43,568 KB
testcase_09 AC 529 ms
43,844 KB
testcase_10 AC 528 ms
43,980 KB
testcase_11 AC 525 ms
43,692 KB
testcase_12 AC 531 ms
43,696 KB
testcase_13 AC 538 ms
43,980 KB
testcase_14 AC 534 ms
43,848 KB
testcase_15 AC 537 ms
43,820 KB
testcase_16 AC 533 ms
43,968 KB
testcase_17 AC 529 ms
43,972 KB
testcase_18 AC 533 ms
43,828 KB
testcase_19 AC 533 ms
43,568 KB
testcase_20 AC 534 ms
44,100 KB
testcase_21 AC 533 ms
43,972 KB
testcase_22 AC 533 ms
43,692 KB
testcase_23 AC 532 ms
43,692 KB
testcase_24 AC 530 ms
43,692 KB
testcase_25 AC 532 ms
43,820 KB
testcase_26 AC 536 ms
43,968 KB
testcase_27 AC 531 ms
43,852 KB
testcase_28 AC 531 ms
44,080 KB
testcase_29 AC 530 ms
43,844 KB
testcase_30 AC 528 ms
43,720 KB
testcase_31 AC 536 ms
43,696 KB
testcase_32 AC 530 ms
43,976 KB
testcase_33 AC 527 ms
43,956 KB
testcase_34 AC 525 ms
43,824 KB
testcase_35 AC 525 ms
43,972 KB
testcase_36 AC 527 ms
43,976 KB
testcase_37 AC 532 ms
44,084 KB
testcase_38 AC 528 ms
43,848 KB
testcase_39 AC 531 ms
44,104 KB
testcase_40 AC 533 ms
43,696 KB
testcase_41 AC 531 ms
43,848 KB
testcase_42 AC 531 ms
43,696 KB
testcase_43 AC 533 ms
43,980 KB
testcase_44 AC 525 ms
43,844 KB
testcase_45 AC 532 ms
43,972 KB
testcase_46 AC 534 ms
43,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N, M, X = map(int, readline().split())
A = list(map(int, readline().split())) + [0]
A = [0] + [x ^ y for x, y in zip(A, A[1:])]

m = map(int, read().split())
graph = [[] for _ in range(N + 1)]
for t, x, y in zip(m, m, m):
    x -= 1
    graph[x].append((y, t))
    graph[y].append((x, t))

C = [0] * (N + 1)
root = [-1] * (N + 1)
is_ng = False
for v in range(N + 1):
    if root[v] != -1:
        continue
    stack = [v]
    root[v] = v
    while stack:
        v = stack.pop()
        for w, x in graph[v]:
            if root[w] == -1:
                root[w] = root[v]
                C[w] = C[v] ^ x
                stack.append(w)
                continue
            if C[w] != C[v] ^ x:
                is_ng = True

if is_ng:
    print(0)
    exit()

for v in range(N + 1):
    X ^= C[v] * A[v]
    if v != root[v]:
        A[root[v]] ^= A[v]


def row_transform_over_F2(A, highest=60):
    for k in range(highest, -1, -1):
        I = np.where((A >> k) == 1)[0]
        if len(I) == 0:
            continue
        i = I[0]
        x = A[i]
        A ^= ((A >> k) & 1) * x
        A[i] = x


nums = np.array([A[v] for v in range(N + 1) if v == root[v] != 0], np.int32)
row_transform_over_F2(nums, 31)
nums.sort()
nums = nums[::-1]

for x in nums:
    if x <= X:
        X ^= x

if X != 0:
    print(0)
else:
    MOD = 10 ** 9 + 7
    free = int(np.sum(nums == 0))
    print(pow(2, free, MOD))
0