結果

問題 No.803 Very Limited Xor Subset
ユーザー 👑 maspymaspy
提出日時 2020-04-14 22:22:09
言語 Python3
(3.8.3 + numpy 1.14.5 + scipy 1.1.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,539 Byte
コンパイル時間 44 ms
使用メモリ 21,296 KB
最終ジャッジ日時 2020-08-08 14:36:07
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 141 ms
21,176 KB
testcase_01 AC 142 ms
21,112 KB
testcase_02 AC 140 ms
21,004 KB
testcase_03 AC 142 ms
21,180 KB
testcase_04 AC 143 ms
21,180 KB
testcase_05 AC 143 ms
21,176 KB
testcase_06 AC 144 ms
21,180 KB
testcase_07 AC 142 ms
21,176 KB
testcase_08 AC 142 ms
21,172 KB
testcase_09 AC 142 ms
21,180 KB
testcase_10 AC 148 ms
21,180 KB
testcase_11 AC 142 ms
21,180 KB
testcase_12 AC 140 ms
21,180 KB
testcase_13 AC 141 ms
21,156 KB
testcase_14 AC 141 ms
21,280 KB
testcase_15 AC 141 ms
21,276 KB
testcase_16 AC 142 ms
21,292 KB
testcase_17 AC 148 ms
21,284 KB
testcase_18 AC 143 ms
21,288 KB
testcase_19 AC 140 ms
21,284 KB
testcase_20 AC 142 ms
21,288 KB
testcase_21 AC 142 ms
21,284 KB
testcase_22 AC 143 ms
21,288 KB
testcase_23 AC 143 ms
21,104 KB
testcase_24 AC 143 ms
21,288 KB
testcase_25 AC 142 ms
21,280 KB
testcase_26 AC 144 ms
21,288 KB
testcase_27 AC 143 ms
21,296 KB
testcase_28 AC 142 ms
21,296 KB
testcase_29 AC 142 ms
21,288 KB
testcase_30 AC 143 ms
21,296 KB
testcase_31 AC 143 ms
21,284 KB
testcase_32 AC 143 ms
21,284 KB
testcase_33 AC 143 ms
21,284 KB
testcase_34 AC 141 ms
21,212 KB
testcase_35 AC 141 ms
21,280 KB
testcase_36 AC 144 ms
21,256 KB
testcase_37 AC 144 ms
21,260 KB
testcase_38 AC 144 ms
21,136 KB
testcase_39 AC 144 ms
21,136 KB
testcase_40 AC 142 ms
21,272 KB
testcase_41 AC 145 ms
21,104 KB
testcase_42 AC 144 ms
21,284 KB
testcase_43 AC 145 ms
21,096 KB
testcase_44 AC 143 ms
21,072 KB
testcase_45 AC 142 ms
21,128 KB
testcase_46 AC 146 ms
21,192 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