結果

問題 No.2377 SUM AND XOR on Tree
ユーザー KowerKoint2010KowerKoint2010
提出日時 2023-06-30 07:07:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 990 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 53,764 KB
最終ジャッジ日時 2023-09-21 05:20:43
合計ジャッジ時間 6,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,280 KB
testcase_01 AC 17 ms
7,836 KB
testcase_02 AC 16 ms
7,904 KB
testcase_03 AC 16 ms
7,880 KB
testcase_04 AC 16 ms
7,844 KB
testcase_05 AC 16 ms
7,788 KB
testcase_06 AC 17 ms
7,836 KB
testcase_07 AC 16 ms
7,904 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
seen = [False] * n
seen[0] = True
postorder = []
child = [[] for _ in range(n)]
stk = [~0, 0]
while stk:
    u = stk.pop()
    if u >= 0:
        for v in g[u]:
            if seen[v]:
                continue
            seen[v] = True
            child[u].append(v)
            stk.append(~v)
            stk.append(v)
    else:
        postorder.append(~u)
a = list(map(int, input().split()))
ans = 0
for k in range(30):
    dp0 = [0] * n
    dp1 = [0] * n
    for u in postorder:
        if a[u] >> k & 1:
            dp1[u] = 1
        else:
            dp0[u] = 1
        for v in child[u]:
            dp0[u], dp1[u] = dp0[u]*dp0[v] + dp1[u]*dp1[v] + dp0[u]*dp1[v], dp0[u]*dp1[v] + dp1[u]*dp0[v] + dp1[u]*dp1[v]
            dp0[u] %= MOD
            dp1[u] %= MOD
    ans += dp1[0] << k
ans %= MOD
print(ans)
0